fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define mod 1000000007
  5. ll po(ll a,ll n){
  6. ll res=a,ans=1;
  7. while(n){
  8. if(n%2) ans=ans*res%mod;
  9. res=res*res%mod;
  10. n/=2;
  11. }
  12. return ans;
  13. }
  14. int main(){
  15. ll mod_4 = po(4,mod-2);
  16. ll n;
  17. cin>>n;
  18. ll k;
  19. if(n%2==0) {k =n/2;
  20. ll res = 9*mod_4;
  21. ll tmp = (po(9,k-1)-1+mod)%mod;
  22. res = res*tmp%mod;
  23. res=(res+3)%mod;
  24. cout<<res;
  25. return 0;
  26. }
  27. else {
  28. k=(n-1)/2;
  29. ll res = mod_4*3;
  30. ll tmp = (po(9,k)-1+mod)%mod;
  31. res = res*tmp%mod;
  32. cout<<res;
  33. return 0;
  34. }
  35. }
Success #stdin #stdout 0s 4948KB
stdin
2
stdout
3