Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. /*
  2.    ¯\_(ツ)_/¯ code written by phamhongquan
  3.    --------------------------------------
  4.    /         VIETNAM REPUBLIC           /
  5.    --------------------------------------
  6.  
  7.           ///,         ////
  8.           \  /,       /  >.
  9.            \  /,    _/  /.
  10.             \_   /_/   /.
  11.              \__/_    <
  12.              /<<< \_\_
  13.             /,)^>>_._  \
  14.              (/  \ /\\
  15.                   // ''''
  16.                   (('
  17.     ( ͡° ͜ʖ ͡°)⌁Vieͥτcͣoͫn🅶⌁
  18.  
  19. */
  20. #define taskname "SQRNUM"
  21.  
  22. #include <iostream>
  23. #include <algorithm>
  24. #include <cmath>
  25. #include <fstream>
  26.  
  27. #define pb push_back
  28. #define fs first
  29. #define sc second
  30.  
  31. using namespace std;
  32. using ll=long long;
  33. using ld=long double;
  34.  
  35. const ll maxn = 1e7 + 2;
  36. const ll mod =  1e9 + 7;
  37. typedef pair<ll,ll> LL;
  38.  
  39. ll t, n, p;
  40. ll limit = 1e7;
  41. bool b[maxn];
  42. vector<LL> nt;
  43. void split(ll n)
  44. {
  45.     for(ll i = 0; nt[i].fs <= n; i++)
  46.     {
  47.         if(i == p) break;
  48.         ll x = nt[i].fs;
  49.         ll y = x;
  50.         while(y <= n)
  51.         {
  52.             nt[i].sc += n/y;
  53.             y *= x;
  54.         }
  55.     }
  56. }
  57. ll nhan(ll x,ll y)
  58. {
  59.     if(y == 0) return 1;
  60.     ll t = nhan(x,y/2);
  61.     if(y % 2 == 0) return(t%mod * t%mod)%mod;
  62.     else return(t%mod * t%mod * x%mod)%mod;
  63. }
  64. int main()
  65. {
  66.     //freopen(taskname".INP", "r", stdin);
  67.     //freopen(taskname".OUT", "w", stdout);
  68.     ios_base::sync_with_stdio(false);
  69.     cin.tie(nullptr);
  70.     cout.tie(nullptr);
  71.     for(ll i = 2; i <= limit; i++)
  72.     {
  73.         if(!b[i])
  74.         {
  75.             for(ll j = i * 2;j <= limit; j += i) b[j] = true;
  76.         }
  77.     }
  78.     for(ll i = 2; i <= limit; i++)
  79.     {
  80.         if (!b[i]) nt.push_back(make_pair(i,0));
  81.     }
  82.     p = nt.size();
  83.     cin >> t;
  84.     for(ll i = 1; i <= t; i++)
  85.     {
  86.         ll res = 1;
  87.         cin >> n;
  88.         for(ll j = 0; j < p; j++) nt[j].sc = 0;
  89.         split(n);
  90.         for(ll j = 0; nt[j].fs <= n; j++)
  91.         {
  92.             if(j == p) break;
  93.             res *= nhan(nt[j].fs,nt[j].sc - nt[j].sc % 2);
  94.             res %= mod;
  95.         }
  96.         cout<<res % mod<<"\n";
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement