Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <fstream>
  5.  
  6. #define pb push_back
  7. #define fs first
  8. #define sc second
  9.  
  10. using namespace std;
  11. using ll=long long;
  12. using ld=long double;
  13.  
  14. const ll maxn = 1e7 + 2;
  15. const ll mod = 1e9 + 7;
  16. typedef pair<ll,ll> LL;
  17.  
  18. ll t, n, p;
  19. ll limit = 1e7;
  20. bool b[maxn];
  21. vector<LL> nt;
  22. void split(ll n)
  23. {
  24. for(ll i = 0; nt[i].fs <= n; i++)
  25. {
  26. if(i == p) break;
  27. ll x = nt[i].fs;
  28. ll y = x;
  29. while(y <= n)
  30. {
  31. nt[i].sc += n/y;
  32. y *= x;
  33. }
  34. }
  35. }
  36. ll nhan(ll x,ll y)
  37. {
  38. if(y == 0) return 1;
  39. ll t = nhan(x,y/2);
  40. if(y % 2 == 0) return(t%mod * t%mod)%mod;
  41. else return(t%mod * t%mod * x%mod)%mod;
  42. }
  43. int main()
  44. {
  45. //freopen(taskname".INP", "r", stdin);
  46. //freopen(taskname".OUT", "w", stdout);
  47. ios_base::sync_with_stdio(false);
  48. cin.tie(nullptr);
  49. cout.tie(nullptr);
  50. for(ll i = 2; i <= limit; i++)
  51. {
  52. if(!b[i])
  53. {
  54. for(ll j = i * 2;j <= limit; j += i) b[j] = true;
  55. }
  56. }
  57. for(ll i = 2; i <= limit; i++)
  58. {
  59. if (!b[i]) nt.push_back(make_pair(i,0));
  60. }
  61. p = nt.size();
  62. cin >> t;
  63. for(ll i = 1; i <= t; i++)
  64. {
  65. ll res = 1;
  66. cin >> n;
  67. for(ll j = 0; j < p; j++) nt[j].sc = 0;
  68. split(n);
  69. for(ll j = 0; nt[j].fs <= n; j++)
  70. {
  71. if(j == p) break;
  72. res *= nhan(nt[j].fs,nt[j].sc - nt[j].sc % 2);
  73. res %= mod;
  74. }
  75. cout<<res % mod<<"\n";
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement