HDU4506 小明系列故事——师兄帮帮忙

问题链接:HDU4506 小明系列故事——师兄帮帮忙

问题描述参见上述链接。

问题分析:(略)。

程序说明:函数powermod()是快速模幂函数。

AC的C++语言程序如下:

/* HDU4506 小明系列故事——师兄帮帮忙 */

#include <iostream>

using namespace std;

typedef unsigned long long ULL;

const ULL MOD = 1000000007;

ULL powermod(ULL a, ULL n, ULL mod)
{
    ULL res = 1L;
    while(n) {
        if(n & 1L) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    int tt, n;
    ULL t, k;
    ULL a[20000], val;

    cin >> tt;
    while(tt--) {
        cin >> n >> t >> k;
        ULL temp = powermod(k, t, MOD);
        for(int i=0; i<n; i++) {
            cin >> val;
            a[(i + t) % n] = val * temp % MOD;
        }

        cout << a[0];
        for(int i=1; i<n; i++)
            cout << " " << a[i];
        cout << endl;
    }

    return 0;
}


posted on 2017-03-23 16:17  海岛Blog  阅读(124)  评论(0编辑  收藏  举报

导航