fork download
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. typedef long long lli;
  6. typedef long double ld;
  7. typedef vector<lli> vi;
  8. typedef pair<lli,lli> ii;
  9.  
  10. #define endl '\n'
  11. #define fore(i,a,b) for(lli i = a; i < b; i++)
  12. #define all(s) begin(s), end(s)
  13. #define sz(s) lli(s.size())
  14. #define f first
  15. #define s second
  16. #define pb push_back
  17. #define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  18.  
  19.  
  20. int const MAXN = 1e7 + 5;
  21. int N[MAXN +5];
  22.  
  23. void f(lli x){
  24.  
  25. if(N[N[x]] > MAXN) return;
  26. N[N[x]] = 3*x;
  27. if(N[N[x]- 1] == 0) N[N[x]- 1] = N[N[x]] - 1;
  28. if(N[N[x]- 2] == 0) N[N[x]- 2] = N[N[x]] - 2;
  29. }
  30.  
  31. int main(){ _
  32. int n;
  33. cin >> n;
  34.  
  35. N[1] = 2;
  36. N[2] = 3;
  37. N[3] = 6;
  38.  
  39. fore(i,3,n){
  40. if(N[i] != 0) f(i);
  41. }
  42.  
  43. cout << N[n]<< endl;
  44.  
  45.  
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
52447