比赛 进阶指南第0章测试 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 魔法部落 最终得分 100
用户昵称 小福鑫 运行时间 0.071 s
代码语言 C++ 内存使用 3.67 MiB
提交时间 2026-03-14 08:45:54
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int n;
int qpow(int a,int b){
    int res=1;
    while(b){
        if(b&1){
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b>>=1;
    }
    return res;
}
signed main(){
    freopen("magic.in","r",stdin);
    freopen("magic.out","w",stdout);
    cin>>n;
    int ans=qpow(3,n+1)-1;
    ans=(ans+mod)%mod;
    cout<<ans*qpow(2,mod-2)%mod;
}