1. 程式人生 > >牛客網小a的旅行計劃

牛客網小a的旅行計劃

地址:https://ac.nowcoder.com/acm/contest/223/B

此題是一道套公式題目,不難,ans=(pow(4,n+1)-4*pow(3,n+1)+6*pow(2,n+1)-4)*pow(8,mod-2)

#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include 
<map> #include <cmath> using namespace std; typedef long long ll; const ll mod=1e8+7; ll qow(ll a,ll b) { if(b==0)return 1; if(b==1)return a%mod; ll sum=qow(a,b/2); return b%2?(a*((sum*sum)%mod))%mod:(sum*sum)%mod; } int main() { ll n; cin>>n; n++; ll ans
=((((qow(4,n)-4*qow(3,n)+6*qow(2,n)-4)%mod+mod)%mod)*qow(8,mod-2))%mod; cout<<ans<<endl; return 0; }