Search found 48 matches

by triplemzim
Sat Apr 20, 2013 2:28 am
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 181968

Re: problem no 100 Time Limit Exceeded

My updated code is here: #include<stdio.h> int len(int x) { int max; max=1; while(x>1) { max++; if(x%2==0) x=x/2; else x=3*x+1; } return max; } int main() { int i,prev,a,b,max,num1,num2; while(scanf("%d %d",&num1,&num2)==2) { max=0; a=len(num1); if(num1==num2) {max=a; goto here;} for(i=num1;i<=num2;...
by triplemzim
Tue Apr 09, 2013 11:22 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 181968

Re: problem no 100 Time Limit Exceeded

I used that loop coz in the problem description it is not clear that how many test cases there are. When i used this : while(scanf("%d %d",&num1,&num2)==2) it runs and works well in my compiler but after submitting here it says compilation error.... :(
by triplemzim
Sat Apr 06, 2013 6:45 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 181968

problem no 100 Time Limit Exceeded

Here is my code: #include<stdio.h> int len(int x) { int max; max=1; while(x>1) { max++; if(x%2==0) x=x/2; else x=3*x+1; } return max; } int main() { int i,prev,a,b,max,num1,num2; while(1){ scanf("%d %d",&num1,&num2); prev=num1; a=len(prev); for(i=num1;i<num2;i++) { b=len(i+1); if(a>b) { max=a; } els...

Go to advanced search