题目链接:传送门
题目大意:求(3^0+3^1+3^2+3^3+...+3^n)%1e9的值
题目思路:乘法逆元裸题
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <cstring> #include <stack> #include <cctype> #include <queue> #include <string> #include <vector> #include <set> #include <map> #include <climits> #define lson root<<1,l,mid #define rson root<<1|1,mid+1,r #define fi first #define se second #define ping(x,y) ((x-y)*(x-y)) #define mst(x,y) memset(x,y,sizeof(x)) #define mcp(x,y) memcpy(x,y,sizeof(y)) using namespace std; #define gamma 0.5772156649015328606065120 #define MOD 1000000007 #define inf 0x3f3f3f3f #define N 1000010 #define maxn 400005 typedef pair<int,int> PII; long long n,m; long long ksm(long long x,long long y){ long long res=1; while(y){ if(y&1)res=res*x%MOD; y>>=1; x=x*x%MOD; } return res; } int main(){ int i,j,group,Case=0; while(cin>>n){ long long temp=ksm(2,MOD-2); n=(ksm(3,n+1)-1+MOD)%MOD; cout<<(n*temp)%MOD<<endl; } return 0; }