[Login|Register]
New post

Show post

Search forum

Read post
Why Runtime Error? [ Topic ] 2013-05-23 13:08:28 qyq79
#include<stdio.h>

long cycle(long n)
{
    long i=1;

    while(n!=1){
        if(n%2==0){
            n=n/2;
            i++;
        }
        else{
        n=n*3+1;
        i++;
        }
    }
    return i;
}

int main()
{
    long i,j,s,max,temp;

    while((scanf("%ld %ld",&i,&j))!=EOF){
        printf("%ld %ld ",i,j);
        if(i>j){
            temp=i;
            i=j;
            j=temp;
        }
        for(max=0;i<=j;i++){
            s=cycle(i);
            if(s>max) max=s;
        }
        printf("%ld\n",max);
    }
}
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.2ms with 2 query(s).