HDU6063 [2017多校联合3] RXD and math 打表 快速幂

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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值