Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <map>
- using namespace std;
- map<int, int> table;
- int calc(int n) {
- int m = table[n];
- if(m) return m;
- return table[n] = (n&1)?2+calc((3*n+1)>>1):1+calc(n>>1);
- }
- int main() {
- table[1] = 1;
- for(int x, y; ~scanf("%d%d", &x, &y);) {
- printf("%d %d ", x, y);
- if(x > y) {
- int t = x; x = y; y = t;
- }
- int ans = 0;
- for(int i = x; i <= y; i++) {
- int l = calc(i);
- if(l > ans) ans = l;
- }
- printf("%d\n", ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement