Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Varianta 1:
- int numar_divizori(int x)
- {
- int c=0,div;
- for (div=1; div * div < x; div++) // div se duce pana la sqrt x
- if (x % div == 0)
- c+=2;
- if ( div * div == x) // in cazul in care e patrat perfect
- c++;
- return c;
- }
- //Varianta 2:
- int number_of_divisors(int x)
- {
- int limit = x;
- int numberOfDivisors = 0;
- if (x == 1) return 1;
- for (int i = 1; i < limit; ++i)
- if (x % i == 0)
- {
- limit = x / i;
- if (limit != i)
- {
- numberOfDivisors++;
- }
- numberOfDivisors++;
- }
- return numberOfDivisors;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement