Programming in UVa
Pages
Home
Programming Tips
Easy List
Books
Codes
Monday, August 25, 2014
UVa Problem No:100 - The 3n + 1 problem
Source code of UVa Online Judge problem number: 100 - The 3n + 1 problem
Problem description:
http://uva.onlinejudge.org/external/1/100.html
////////////////////////////////////////////// // Bismillahir Rahmanir Rahim // // Author : Shohan Ahmed Sijan // // Country : Bangladesh // // University : East West University // ///////////////////////////////////////// #include
int main() { long long i,j,max,temp,count,ii; while(scanf("%ld %ld",&ii,&j)!=EOF) { printf("%ld %ld",ii,j); if(ii>j) { temp = ii; ii = j; j = temp; } max = 0; for(i=ii;i<=j;i++) { temp = i; count = 1; if(temp>1) { do { if(temp%2==0) temp=temp/2; else temp=temp*3+1; count++; }while(temp!=1); } if(count>max) max = count; } printf(" %ld\n",max); } return 0; }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
Followers
No comments:
Post a Comment