Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int mx = 10000025;
- const long long mod = 1000000007;
- int prime[mx], totient[mx], lp[mx], f[mx], facto[mx];
- long long power(long long x, long long y)
- {
- long long res = 1;
- x = x % mod;
- while (y > 0)
- {
- if (y & 1)
- res = (res * x) % mod;
- y = y >> 1;
- x = (x * x) % mod;
- }
- return res%mod;
- }
- void isPrime()
- {
- for(int i = 2; i < mx; i ++)
- {
- if(!prime[i])
- {
- lp[i] = i;
- for(int j = i + i; j < mx; j += i)
- {
- prime[j] = 1;
- lp[j] = i;
- }
- }
- for(int i = 2; i < mx; i ++)
- {
- prime[i] = prime[i - 1] + 1 - prime[i];
- }
- }
- }
- void phi()
- {
- totient[1] = 1;
- for(int i = 2; i < mx; i ++)
- {
- int j = i / lp[i];
- if(j % lp[i] == 0)
- {
- totient[i] = totient[j] * lp[i];
- }
- else
- {
- totient[i] = totient[j] * (lp[i] - 1);
- }
- }
- for(int i = 1; i < mx; i ++){
- f[i] = prime[i] - totient[i];
- if(f[i] < 0){
- f[i] = 0;
- }
- }
- }
- void modfactot()
- {
- facto[0] = 1;
- for(int i = 1; i < mx; i ++){
- facto[i] = 1LL * facto[i - 1] * i % (mod - 1);
- }
- }
- int main()
- {
- isPrime();
- phi();
- modfactot();
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- cout<<power(totient[n],facto[f[n]])<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement