Advertisement
momo2345

Number of divisors

May 5th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  4. #define ll long long
  5. #define pb push_back
  6. #define endl "\n"
  7. const int mx = 1e7+123;
  8. bitset<mx> is_prime;
  9. vector<int> prime;
  10.  
  11. void primegen ( int n )
  12. {
  13.     n += 100;
  14.     for ( int i = 3; i <= n; i += 2 ) is_prime[i] = 1;
  15.  
  16.     int sq = sqrt ( n );
  17.     for ( int i = 3; i <= sq; i += 2 ) {
  18.         if ( is_prime[i] == 1 ) {
  19.             for ( int j = i*i; j <= n; j += ( i + i ) ) {
  20.                 is_prime[j] = 0;
  21.             }
  22.         }
  23.     }
  24.  
  25.     is_prime[2] = 1;
  26.     prime.push_back (2);
  27.  
  28.     for ( int i = 3; i <= n; i += 2 ) {
  29.         if ( is_prime[i] == 1 ) prime.push_back ( i );
  30.     }
  31. }
  32. ll NOD(ll l)
  33. {
  34.      int ret=1,cnt=1;
  35.     for(auto p: prime)
  36.     {
  37.         if(1LL*p*p >l) break;
  38.         if(l%p==0)
  39.         {
  40.              cnt=1;
  41.             while(l%p==0)
  42.             {
  43.                 cnt++;
  44.                 l/=p;
  45.             }
  46.         ret*=cnt;
  47.         }
  48.     }
  49.     if(l>1) ret*=2;
  50.     return ret;
  51. }
  52. int main()
  53. {
  54.     suni;
  55.     primegen(1e6);
  56.     int t; cin>>t;
  57.     while(t--){
  58.     ll n;
  59.     cin>>n;
  60.     cout<<NOD(n)<<endl;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement