Ci mette troppo e ho provato di tutto, che altra strategia consigliate?
#include<bits/stdc++.h>
using namespace std;
const long long int mod=1000000007;
long long int power(long long int base, long long int esponente) {
long long int result = 1;
base%=mod;
while (esponente>0) {
if (esponente%2==1) {
result=(result*base) % mod;
}
base = (base*base)%mod;
esponente/=2;
}
return result;
}
vector<int> execute(int N, int K,int D, vector<int> A) {
vector<int> B(N,1);
if(D==0){
for (int i = 0; i < N; ++i) {
B[i] = power(A[i],K);
}
}else{
for (int Q = 0; Q < K; ++Q) {
for(int i=0;i<N;i++){
B[i] = ((B[i]%mod)*(A[(i+D*Q)%N]%mod))%mod;
}
}
}
return B;
}
int main() {
int N, K, D;
cin >> N >> K >> D;
int u;
vector<int> A(N);
for (int x=0;x<N;x++){
cin >> u;
A[x]=u;
}
vector<int> B = execute(N, K, D, A);
for (size_t i = 0; i < B.size(); ++i) {
cout << B[i];
if (i + 1 < B.size()) std::cout << " ";
}
cout <<endl;
}