Problem Description
RXD is a good mathematician.
One day he wants to calculate:
One day he wants to calculate:
∑i=1nkμ2(i)×⌊nki−−−√⌋
output the answer module 109+7.
1≤n,k≤1018
μ(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.
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%MOD
记得对n先做预处理取模,否则快速幂也救不了啊
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const long long MOD=1e9+; long long quickmod(long long a,long long b,long long m)
{
long long ans = ;
while(b)//用一个循环从右到左遍历b的所有二进制位
{
if(b&)//判断此时b[i]的二进制位是否为1
{
ans = (ans*a)%m;//乘到结果上,这里a是a^(2^i)%m
b--;//把该为变0
}
b/=;
a = a*a%m;
}
return ans;
} int main()
{
long long n,k;
int t=;
while(~scanf("%lld%lld",&n,&k))
{
printf("Case #%d: ",t++);
n%=MOD;
printf("%lld\n",quickmod(n,k,MOD));
}
return ;
}
打表程序如下:
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std; #define MOD 1000000000+7 bool panduan (long long num)
{
long long i;
for(i=;i<=sqrt((double)num)+;i++)
{
if(num%(i*i)==)
return true;
}
return false;
} int main()
{
int n,k;
long long num;
long long res=;
for(int n=;n<=;n++)
for(int k=;k<=;k++)
{
res=;
num=pow((double)n,(double)k);
for(int i=;i<=num;i++)
{
if(!panduan(i))
res+=(long long)(sqrt((double)(num/i)));
res%=MOD;
}
printf("%d %d %lld\n",n,k,res);
}
return ;
}
每一行三个数字分别表示n,k,res