RXD and math http://acm.hdu.edu.cn/showproblem.php?pid=6063
一言不合就打表
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int Q = 1e9+7;
LL m[100000+10];
LL quick_power (LL x, LL y)
{
LL ret = 1;
while (y > 0){
x %= Q;
if (y & 1)
ret = ret * x % Q;
y >>= 1;
x = x * x % Q;
}
return ret;
}
void mu(LL x)//莫比乌斯函数实现
{
m[1]=1;
for(LL i=1; i<=x; i++)
for(LL j=2*i; j<=x; j+=i)
{
m[j]-=m[i];
}
}
int main ()
{
memset (m, 0, sizeof (m));
mu (100000);
/*for (int i=0; i<100; ++i){
cout << mu[i] << " " <<endl;
}*/
cout << "n" << "______" << "k" << "_______" << "ans" << endl;
for (int n=1; n<=5; ++n){
for (int k=1; k<=5; ++k){
LL ans = 0;
LL x = quick_power (n, k);
for (int r=1; r<=x; ++r){
ans += m[r] * m[r] * floor(sqrt(x * 1.0 / r));
}
cout << n << "______" << k << "_______" << ans << endl;
}
}
return 0;
}
发现运行的结果是n的k次幂,于是上模板
# include <bits/stdc++.h>//万能头文件,编译时间长
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int Q = 1e9+7;
LL quick_power (LL x, LL y)//快速幂
{
LL ret = 1;
while (y > 0)
{
x %= Q;
if (y & 1)
ret = ret * x % Q;
y >>= 1;
x = x * x % Q;
}
return ret;
}
int main ()
{
LL n, k, Case = 1;
while (scanf ("%lld%lld", &n, &k) != EOF)
{
LL ans = quick_power (n, k);
printf ("Case #%lld: %lld\n", Case++, ans);
}
return 0;
}