Guest User

Untitled

a guest
Jun 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #define MAXN 1000000
  4. using namespace std;
  5.  
  6. int L[MAXN];
  7.  
  8. int cal(int x){
  9.     if(x >= MAXN) return (x&1)?cal(3*x+1):cal(x>>=1);
  10.     if(L[x] != 0) return L[x];
  11.     L[x] = (x&1)?cal(3*x+1):cal(x>>1);
  12.     return L[x];
  13. }
  14.  
  15. int main(){
  16.     L[1] = 1;
  17.     for(int i=2;i<MAXN;++i) cal(i);
  18.     printf("done\n");
  19. //  system("pause");
  20. }
Add Comment
Please, Sign In to add comment