![]() ![]() |
PDF (English) | Statistics | Forum |
Time Limit: 1 second(s) | Memory Limit: 32 MB |
Sometimes it's quite useful to write pseudo codes forproblems. Actually you can write the necessary steps to solve a particularproblem. In this problem you are given a pseudo code to solve a problem and youhave to implement the pseudo code efficiently. Simple! Isn't it? :)
pseudo code
{
take two integers n and m
let p = n ^ m (n tothe power m)
let sum = summation of all thedivisors of p
let result = sum MODULO1000,000,007
}
Now given n and m you have to find the desiredresult from the pseudo code. For example if n = 12 and m = 2.Then if we follow the pseudo code, we get
pseudo code
{
take two integers n and m
so, n = 12 and m = 2
let p = n ^ m (n tothe power m)
so, p = 144
let sum = summation of all thedivisors of p
so, sum = 403, since the divisors ofp are 1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 36, 48, 72, 144
let result = sum MODULO1000,000,007
so, result = 403
}
Input starts with an integer T (≤ 5000),denoting the number of test cases.
Each test case will contain two integers, n (1 ≤ n)and m (0 ≤ m). Each of n and m will be fit into a 32bit signed integer.
For each case of input you have to print the case number andthe result according to the pseudo code.
Sample Input |
Output for Sample Input |
3 12 2 12 1 36 2 |
Case 1: 403 Case 2: 28 Case 3: 3751 |
#include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 1000100 #define LL long long #define ll __int64 #define INF 0x7fffffff #define mem(x) memset(x,0,sizeof(x)) #define PI acos(-1) #define eps 1e-10 using namespace std; int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a/gcd(a,b)*b;} LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} //head struct s { int num; int cnt; }p[MAXN]; int prime[MAXN]; int v[MAXN]; int q; LL fun(LL a,LL n,LL MOD) { if(n==0) return 1; if(n%2) return ((1+powmod(a,n/2+1,MOD))%MOD*fun(a,n/2,MOD)%MOD)%MOD; else return (powmod(a,n/2,MOD)+(1+powmod(a,n/2+1,MOD))%MOD*fun(a,(n-1)/2,MOD)%MOD)%MOD; } void db() { int i,j; q=0; mem(v); for(i=2;i<=100000;i++) { if(!v[i]) { prime[q++]=i; for(j=i*2;j<=100000;j+=i) v[j]=1; } } } int main() { db(); LL a,b,i; int tt,cas=0; scanf("%d",&tt); while(tt--) { scanf("%lld%lld",&a,&b); int x=a; int ccnt=0; for(i=0;i<q&&prime[i]*prime[i]<=x;i++) { if(x%prime[i]==0) { p[ccnt].num=prime[i]; int t=0; while(x%prime[i]==0) x/=prime[i],t++; p[ccnt++].cnt=t; } if(x==1) break; } if(x!=1) { p[ccnt].num=x; p[ccnt].cnt=1; ccnt++; } LL ans=1; for(i=0;i<ccnt;i++) ans=(ans*fun(p[i].num,p[i].cnt*b,1000000007))%1000000007; printf("Case %d: ",++cas); printf("%lld\n",ans); } return 0; }