Advertisement
BatedCrayon

MaxD (OJI 2005 - Clasa a 9-a)

Mar 21st, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <fstream>
  2. #define UI unsigned int
  3.  
  4. using namespace std;
  5.  
  6. ifstream in("maxd.in");
  7. ofstream out("maxd.out");
  8.  
  9. UI NrDiv(UI x)
  10. {
  11.     unsigned int e,p,d;
  12.     e=0;
  13.     while(x%2==0)
  14.     {
  15.         x/=2;
  16.         e++;
  17.     }
  18.     p=e+1;
  19.     for(d=3; x>1 && d*d<=x; d+=2)
  20.     {
  21.         e=0;
  22.         while(x%d==0)
  23.         {
  24.             x/=d;
  25.             e++;
  26.         }
  27.         p*=(e+1);
  28.     }
  29.     if(x>1)
  30.         p*=2;
  31.     return p;
  32.  
  33. }
  34.  
  35. UI minim,nrdiv,contor,a,b,i;
  36.  
  37. int main()
  38. {
  39.     in>>a>>b;
  40.     minim=a;
  41.     nrdiv=NrDiv(a);
  42.     contor=1;
  43.     for(i=a+1; i<=b; i++)
  44.     {
  45.         if(nrdiv<NrDiv(i))
  46.         {
  47.             nrdiv=NrDiv(i);
  48.             minim=i;
  49.             contor=1;
  50.         }
  51.         else
  52.         {
  53.             if(nrdiv==NrDiv(i))
  54.                 contor++;
  55.         }
  56.     }
  57.     out<<minim<<" "<<nrdiv<<" "<<contor;
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement