Advertisement
BatedCrayon

Numarul de divizori (Determinare eficienta)

May 20th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. /* ATENTIE! Acesta este un subprogram. Pentru a il utiliza, lipeste-l in sursa ta si apeleaza functia! */
  2. unsigned int nrdiv(unsigned int a)
  3. {
  4.     unsigned int e,d,rez;
  5.     e=0;
  6.     while(a%2==0)
  7.     {
  8.         a/=2;
  9.         e++;
  10.     }
  11.     rez=e+1;
  12.     d=3;
  13.     while(a>1 && d*d<=a)
  14.     {
  15.         e=0;
  16.         while(a%d==0)
  17.         {
  18.             a/=d;
  19.             e++;
  20.         }
  21.         rez*=(e+1);
  22.         d+=2;
  23.     }
  24.     if(a>1)
  25.         rez*=2;
  26.     return rez;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement