题意:给定一个公式,给出上限的两个参数n,k,上限为n^k,问公式的答案。
解法:答案就是n^k啦。为什么呢?
因为,对于每一个大于零的自然数x,一定可以将它分解成唯一的a^2*b的形式,其中u(b)!=0,即u(b)^2=1,函数u为莫比乌斯函数。
公式中根号项表示的是,对于一个特定的i,满足a^2<=n^k/i的a的个数,即满足x=a^2*i且x<=n^k的x个数。枚举1到n^k的i即枚举所有可能的b,故1~n^k的每个数在求和式里的贡献都是1,答案就是n^k啦。快速幂求一下n^k的值就可以了。
于是上代码:
#include <bits/stdc++.h>
using namespace std;
int cas;
const long long mod=1e9+7;
long long ksm(long long x,long long n) {
long long ret=1;
while (n) {
if (n&1)
ret=ret*x%mod;
n>>=1;
x=x*x%mod;
}
return ret;
}
int main()
{
long long n,k;
while (scanf("%I64d%I64d",&n,&k)==2) {
++cas;
printf("Case #%d: %I64d\n",cas,ksm(n%mod,k));
}
return 0;
}