Advertisement
Cucura_Georgiana

Varianta 2019, Subiect 3

Nov 20th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. (Sesiunea august-septembrie, 26 august 2019)
  2.  
  3. 1.  #include<iostream>
  4. #include<cmath>
  5. using namespace std;
  6. int produs (int x)
  7. {
  8.     int p=1, d, r;
  9.     r=sqrt(x);
  10.     for(d=1; d<=r; d=d+2)
  11.     {
  12.         if(x%d==0)
  13.         {
  14.             p=p*d;
  15.             if(p>1)
  16.             {
  17.                 return p;
  18.             }
  19.         }
  20.         if(x%(x/d)==0 && d!=x/d)
  21.         {
  22.             p=p*(x/d);
  23.             if(p>x)
  24.             {
  25.                 return p;
  26.             }
  27.         }
  28.     }
  29.     return p;
  30. }
  31. int MaxImp (int a, int b)
  32. {
  33.     int i;
  34.     for(i=b; i>=a; i--)
  35.     {
  36.         if(produs(i)>i)
  37.         {
  38.             return i;
  39.         }
  40.     }
  41.     return 0;
  42. }
  43. int main()
  44. {
  45.     int a, b;
  46.     cin>>a>>b;
  47.     cout<<MaxImp(a, b);
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement