Problem Description
RXD is a good mathematician.
One day he wants to calculate:
output the answer module 10^9+7.
1≤n,k≤10^18
μ(n)=1(n=1)
μ(n)=(−1)k(n=p1p2…pk)
μ(n)=0(otherwise)
p1,p2,p3…pk 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
Source
2017 Multi-University Training Contest - Team 3
题意:
求公式的值,μ(x)就是莫比乌斯函数。
想法:
先打表,求出1-10的n,1-5的k对应的结果:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll quickmod(ll a,ll b)
{
ll ans=1;
a%=mod;
while(b>0)
{
if(b&1)
{
ans=(ans*a)%mod;
}
b/=2;
a=(a*a)%mod;
}
return ans;
}
int main()
{
ll n,k;
int cas=1;
while(~scanf("%lld%lld",&n,&k))
{
printf("Case #%d: %lld\n",cas++,quickmod(n,k));
}
}
结果为:
我们发现结果就是
nk
,所以就愉快的套快速幂的模板辣~
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll quickmod(ll a,ll b)
{
ll ans=1;
a%=mod;
while(b>0)
{
if(b&1)
{
ans=(ans*a)%mod;
}
b/=2;
a=(a*a)%mod;
}
return ans;
}
int main()
{
ll n,k;
int cas=1;
while(~scanf("%lld%lld",&n,&k))
{///cnt要定义在外面zz
printf("Case #%d: %lld\n",cas++,quickmod(n,k));
}
}
ps:打表get√