比赛 进阶指南第0章测试 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 魔法部落 最终得分 100
用户昵称 rzzakioi 运行时间 0.037 s
代码语言 C++ 内存使用 1.63 MiB
提交时间 2026-03-14 08:42:08
显示代码纯文本
#include<cstdio>
#define int long long
using namespace std;
const int mod=1e9+7;
int n;
int fpow(int x,int y){
    int ans=1;
    while(y){
        if(y&1){
            ans*=x;
            ans%=mod;
        }
        x*=x;
        x%=mod;
        y>>=1;
    }
    return ans;
}
signed main(){
    freopen("magic.in","r",stdin);
    freopen("magic.out","w",stdout);
    scanf("%lld",&n);
    int ans=fpow(3,n+1);
    ans=((ans-1)%mod+mod)%mod;
    ans*=fpow(2,mod-2);
    ans%=mod;
    printf("%lld",ans);
    return 0;
}