Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- //UVA Problem 100 (3n+1)
- int main() {
- long long n, i, j;
- while(cin>>i>>j) {
- long long mx=0;
- for(int k=i;k<=j;k++){
- long long count = 0;
- n = k;
- while(1){
- count++;
- if(count>=mx) mx = count;
- if(n==1) break;
- if(n%2 == 0) {
- n = n/2;
- } else {
- n = 3*n + 1;
- }
- }
- }
- cout<<i<<" "<<j<<" "<<mx<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement