問題鏈接: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;
}