Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // 3n_plus_1
- //
- // Created by Vincent Liu on 2017/10/13.
- // Copyright © 2017年 Vincent Liu. All rights reserved.
- //
- #include <stdio.h>
- int main(int argc, const char * argv[]) {
- int start, end, i, step, input, max, a, b;
- while(scanf("%d %d", &a, &b) != EOF) {
- max = 0;
- if (a <= b) {
- start = a;
- end = b;
- }
- else {
- end = a;
- start = b;
- }
- for(i = start; i <= end; i++) {
- input = i;
- step = 1;
- while(input != 1) {
- if(input % 2 == 0) {
- input = input / 2;
- }
- else {
- input = input * 3 + 1;
- }
- step++;
- }
- if(step > max){
- max = step;
- }
- }
- printf("%d %d %d\n", a, b, max);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement