Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int main() {
- int memo[1000000] = {};
- while (true) {
- int cycle = 0;
- int m,n;
- cin>>m>>n;
- for (int i = m; i <= n; ++i) {
- int n = i;
- // cout << n << " ";
- int count = 1;
- if (memo[n] == 0) {
- while (n != 1) {
- //if (memo[n] != 0) {
- if (n % 2 == 1)
- n = 3 * n + 1;
- else
- n = n / 2;
- // cout << n << " ";
- count++;
- // } else {
- //count += memo[n];
- // break;
- //}
- }
- }
- memo[i] = count;
- // cout << ": " << count<<endl;
- if (cycle < count)
- cycle = count;
- }
- cout << m << " " << n << " " << cycle << endl;
- for (int i = 1; i <=1000 ; ++i) {
- cout<<i<<" : "<<memo[i]<<", ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement