Advertisement
BojidarDosev

Find the number of dividers of a number

Nov 27th, 2023
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //funkciq za namirane na broqt na delitelite
  5. int br_deliteli(int n)
  6. {
  7.     int result = 1;
  8.     for (int i = 2; i * i <= n; ++i)
  9.     {
  10.         int br = 0;
  11.         while (n % i == 0)
  12.         {
  13.             n /= i;
  14.             br++;
  15.         }
  16.         result *= (br + 1);
  17.     }
  18.     if (n > 1)
  19.     {
  20.         result *= 2;
  21.     }
  22.     return result;
  23. }
  24.  
  25. int main()
  26. {
  27.     //vuvejdane na chislo
  28.     int n;
  29.     cin >> n;
  30.     //proverka dali popada v intervala
  31.     if (n < 2 || n > 2000)
  32.     {
  33.         cout << "Invalid input data!";
  34.         return 0;
  35.     }
  36.     cout << br_deliteli(n);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement