Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int count_step(long long int n)
- {
- long long int c = 1;
- while(n != 1)
- {
- if(n % 2 == 0)
- {
- n = n / 2;
- }
- else
- {
- n = 3 * n + 1;
- }
- c++;
- }
- return c;
- }
- int main()
- {
- long long int a, b, max, i;
- while(scanf("%lld %lld", &a, &b) == 2)
- {
- if(a >= b)
- {
- max = 0;
- for(i = b; i <=a; i++)
- {
- if(count_step(i) > max)
- {
- max = count_step(i);
- }
- }
- printf("%lld %lld %lld\n",a, b, max);
- }
- if(a < b)
- {
- max = 0;
- for(i = a; i < b; i++)
- {
- if(count_step(i) > max)
- {
- max = count_step(i);
- }
- }
- printf("%lld %lld %lld\n",a, b, max);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement