题解:SP25337 NPC2015D - Eefun is not so Fun
主要思路
在同样和为
此外,在剩余
注意到数据范围是
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int ksm(int m,int k){
int res=1%mod,t=m;
while(k){
if(k&1){
res=res*t%mod;
}
t=t*t%mod;
k>>=1;
}
return res;
}
signed main(){
int n;
cin>>n;
if(n%3==1){
cout<<(4*ksm(3,n/3-1))%mod<<'\n';
}else if(n%3==2){
cout<<(2*ksm(3,n/3))%mod<<'\n';
}else cout<<ksm(3,n/3)<<'\n';
return 0;
}