题解 | 小红的二叉树
小红的二叉树
https://www.nowcoder.com/practice/ee287e0f6af64edd969f01444dd763e4
//不能用cmath中的pow,会超过double的最大范围
#include <iostream>
#include <cmath>
using namespace std;
const int mod = 1e9+7;
int main() {
int N;
cin>>N;
if(N<=2){
switch (N) {
case 1:cout<<0;return 0;
case 2:cout<<1;return 0;
}
}
long long ans = 1,yezi = 2;
for(int i = 2;i<N;i++){
ans = (ans+3*yezi)%mod;
yezi = (yezi*2)%mod;
//cout<<ans%mod<<endl;
}
cout<<ans%mod;
return 0;
}
