Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #define MAXN 1000000
- using namespace std;
- int L[MAXN];
- int cal(int x){
- if(x >= MAXN) return (x&1)?cal(3*x+1):cal(x>>=1);
- if(L[x] != 0) return L[x];
- L[x] = (x&1)?cal(3*x+1):cal(x>>1);
- return L[x];
- }
- int main(){
- L[1] = 1;
- for(int i=2;i<MAXN;++i) cal(i);
- printf("done\n");
- // system("pause");
- }
Add Comment
Please, Sign In to add comment