比赛 进阶指南第0章测试 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 魔法部落 最终得分 100
用户昵称 2_16鸡扒拌面 运行时间 0.072 s
代码语言 C++ 内存使用 3.69 MiB
提交时间 2026-03-14 08:38:50
显示代码纯文本
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;

ll n,p,ans;

ll ksm(ll a,ll b,ll p)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%p;
		a=a*a%p;
		b>>=1;
	}
	return res;
}

int main()
{
	freopen("magic.in","r",stdin);
	freopen("magic.out","w",stdout);
	cin>>n;
	p=ksm(3,n+1,mod);
	ans=(p-1+mod)%mod*ksm(2,mod-2,mod)%mod;
	cout<<ans;
	return 0;
}