RXD and math

来源:互联网 发布:吉比特和电魂网络比较 编辑:程序博客网 时间:2024/06/05 17:44

RXD and math

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 953    Accepted Submission(s): 520


Problem Description
RXD is a good mathematician.
One day he wants to calculate:
i=1nkμ2(i)×nki

output the answer module 109+7.
1n,k1018
μ(n)=1(n=1)

μ(n)=(1)k(n=p1p2pk)

μ(n)=0(otherwise)

p1,p2,p3pk are different prime numbers
 

Input
There are several test cases, please keep reading until EOF.
There are exact 10000 cases.
For each test case, there are 2 numbers n,k.
 

Output
For each test case, output "Case #x: y", which means the test case number and the answer.
 

Sample Input
10 10
 

Sample Output
Case #1: 999999937
 

题意:

     给出n,k,计算公式的值,其中u(i)为莫比乌斯函数。

思路:

     暴力打表找规律,发现公式的结果恰好为n^k,直接用快速幂求结果。

下面贴上代码:

#include<cstdio>using namespace std;typedef long long LL;const int INF=0x3f3f3f3f;const int mod=1e9+7;LL quickpow(LL a,LL b) //快速幂{    if(b<0)        return 0;    LL ret=1;    a%=mod;    while(b)    {        if(b & 1)            ret=(ret*a)%mod;        b>>=1;        a=(a*a)%mod;    }    return ret;}int main (){    LL n,k,cas=1;    while(scanf("%lld%lld",&n,&k)!=EOF)    {        LL ans=quickpow(n,k);        printf("Case #%lld: %lld\n",cas++,ans);    }    return 0;}






原创粉丝点击