HDU6063 2017杭电多校联赛第三场-RXD and math

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hfuu1504011020/article/details/76639505

题目大意:就是给我们一个数学公式,由这个公式求所有项的和。
解题思想:起初我们在解这道题时想到的是利用莫比乌斯函数看最终能推导出什么规律,费了一段时间失败了,之后看有挺多人过了,然后我们就打了个表,实验了一些数据发现可以,规律啥的网上都有,代码也很简单,就不多说,我想说的是当我们处理一些问题时,有时可以大胆的去猜测,不会用好的方法时,我们可以去暴力,枚举,有些看似复杂的问题都是可以解决的,而暴力,枚举的难点在于,你需要证明这个问题使用此方法是可行的。这就需要我们多多练习喽。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define Mod 1e9+7
LL N,K,ans;
 LL power2(LL a, LL b, LL c)
{
    LL res = 1;
    a %= c;
    while (b)
    {
        if (b & 1)
            res = (res * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return res;
}
int main()
{
    int cnt=0;
    while(~scanf("%lld%lld",&N,&K))
    {
        printf("Case #%d: %lld\n",++cnt,power2(N,K,Mod));
    }

    return 0;
}

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6063

猜你喜欢

转载自blog.csdn.net/hfuu1504011020/article/details/76639505