Page 40 - MATINF Nr. 8
P. 40

40                                                           5  IMPLEMENTARE S , I REZULTATE



            5.2     Implementarea algoritmului 3



            # include <iostream >
            # include <math.h>
             using namespace std;


             int n, a[100] , m, b[100] , u, v;
             void read_data (){
             int i;
            cin >>n;
             for(i=0;i<=n;i++)
                  cin >>a[i];
            cin >>m;
             for(i=0;i<=m;i++)
                  cin >>b[i];
            cin >>u>>v;
            }
             unsigned long long f(int n, int a[],int x){
             unsigned long long s = 0;
             int i;
             for(i=n;i >=0;i--)
                  s = a[i] + x * s;
             return s;
            }
             void solve_ec1(int n, int a[], int y, int u, int v){
             int x;
             unsigned long long s;
             for(x=1;x<= fabs(a[0])/2;x++){
                  s = f(n,a,x);
                  if(s == 0 && x>=u && x<=v)
                        cout <<x<<"␣"<<y<<endl;
                  s = f(n,a,-x);
                  if(s == 0 && -x>=u && -x<=v)
                        cout <<-x<<"␣"<<y<<endl;
            }
            x = fabs(a[0]);
            s = f(n,a,x);
            if(s == 0 && x>=u && x<=v)
                  cout <<x<<"␣"<<y<<endl;
            if(a[0]!=0){
                  s = f(n,a,-x);
                  if(s == 0 && -x>=u && -x<=v)
                        cout <<-x<<"␣"<<y<<endl;
            }
            }
             void solve_ec2(int n, int a[], int m, int b[], int u, int v){
             int c[100] ,i,y;
             for(i=1;i<=n;i++)
                        c[i] = a[i];
             for(y=u;y<=v;y++){
                  c[0] = a[0] + f(m,b,y);
                  solve_ec1(n,c,y,u,v);
            }
            }
             int main ()
            {
   35   36   37   38   39   40   41   42   43   44   45