本文共 955 字,大约阅读时间需要 3 分钟。
很容易推出来的公式ans=n^(k-1)*k*sum
然后快速幂就好了
#include#include #include #include #include #include #include #include #include #include #include #include #include #define pi acos(-1.0)#define ll long long#define mod 1000000007#define ls l,m,rt<<1#define rs m+1,r,rt<<1|1#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const double g=10.0,eps=1e-7;const int N=10000+10,maxn=500+100,inf=0x3f3f3f;ll a[N];ll quickmul(ll a,ll b,ll mo){ ll ans=1; while(b){ if(b&1)ans=(ans*a)%mo; a=(a*a)%mo; b/=2; } return ans%mo;}int main(){ ios::sync_with_stdio(false); cin.tie(0); ll t,cnt=0; cin>>t; while(t--){ ll n,k,mo,sum=0; cin>>n>>k>>mo; for(int i=0;i >a[i]; sum=(sum+a[i])%mo; } ll ans=quickmul(n,k-1,mo); ans=(ans*k)%mo; ans=(ans*sum)%mo; cout<<"Case "<<++cnt<<": "< <
转载于:https://www.cnblogs.com/acjiumeng/p/7227374.html