Advertisement
fooker

number of divisors (O(sqrt(n) time complex)

Nov 19th, 2022
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     int n;
  5.     cin >> n;
  6.     for (int q = 0; q < n; q++) {
  7.         int x;
  8.         int div_num = 0;
  9.         cin >> x;
  10.         for (int i = 1; i * i <= x; i++) {
  11.             if (x % i == 0) {
  12.                 div_num += i * i == x ? 1 : 2;
  13.             }
  14.         }
  15.         cout << div_num << '\n';
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement