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
一看就懂不用多说了吧。
思路:
官方题解:
实际上答案大家都是知道的,我们来推一推为什么
既然x=a^2*b(b为无平方因子数),且μ(b)^2一定为1(仔细想想μ(i)的定义),令n^k=a^2*i,我们枚举的是i,由于a=,且1到n^k的每个数可以唯一表示成a^2*i 的形式,每次枚举i,我们就可以得到a个可由a^2*i(x=1^2*i,x=2^2*i......x=a^2*i)组成的数,当枚举下一个i时,一定不会存在a^2*i与前面的x重复的情况,因此该公式计算的是1到n^k有多少个数。
注意:如果一开始n很大要对它取模。
示例程序
/*
Problem : 6063 ( RXD and math ) Judge Status : Accepted
RunId : 21449305 Language : G++ Code Len : 470 B
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
*/
#include <cstdio>
#define LDQ 1000000007
using namespace std;
long long quick(long long x,long long k)
{
long long t=x,ans=1;
while(k!=0)
{
if(k%2==1)
{
ans=(ans*t)%LDQ;
}
t=(t*t)%LDQ;
k=k/2;
}
return ans;
}
int main()
{
long long n,k;
for(int i=1;scanf("%lld %lld",&n,&k)!=EOF;i++)
{
printf("Case #%d: %lld\n",i,quick(n%LDQ,k));
}
return 0;
}