fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int inf=1e9;
  4. unsigned long long int pow(unsigned long long int a,unsigned long long int b){
  5. unsigned long long int res=1;
  6. while(b){
  7. if(b&1)res=res*a;
  8. a=a*a;
  9. b/=2;
  10. }
  11. return res;
  12. }
  13. int main(){
  14. int t;
  15. cin>>t;
  16. while(t--){
  17. int n;
  18. cin>>n;
  19. unsigned long long int p=pow(3,n);
  20. if(n>=3){
  21. cout<<p-6<<endl;
  22. }
  23. else cout<<p<<endl;
  24. }
  25. }
Success #stdin #stdout 0s 3464KB
stdin
15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
stdout
3
9
21
75
237
723
2181
6555
19677
59043
177141
531435
1594317
4782963
14348901