Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- /*
- 令f(x)為求0~x之間0的個數有多少,
- 即可將題目換化成[m,n]之間0的個數=f(n)-f(m-1)。
- */
- int f( int n )
- {
- if( n == 1 )
- return 1;
- else if( n % 2 == 1)
- return f( 3*n+1 )+1;
- else
- return f( n/2 )+1;
- }
- int main()
- {
- int i, j;
- while( cin >> i >> j )
- {
- int minNum = min( i, j );
- int maxNum = max( i, j );
- int answer = 0;
- for( int n = minNum ; n <= maxNum ; n++ ){
- answer = max( answer, f(n) );
- }
- cout << i << ' ' << j << ' ' << answer << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement