694 - The Collatz Sequence
2014-09-10 16:13
281 查看
#include<stdio.h>
int collatz( long long m,long long n,intcount)
{
count++;
if(m==1) return count;
if(m>n) return--count;
if(m%2==0)
collatz(m/2,n,count);
else
collatz(m*3+1,n,count);
}
int main()
{
long long m,n;
int i=0,count=0;
while(1)
{
i++;
scanf("%lld%lld",&m,&n);
if(m<0&&n<0)break;
printf("Case %d: A = %lld, limit = %lld,",i,m,n);
printf("number of terms =%d\n",collatz(m,n,count));
}
return 0;
}
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=635
int collatz( long long m,long long n,intcount)
{
count++;
if(m==1) return count;
if(m>n) return--count;
if(m%2==0)
collatz(m/2,n,count);
else
collatz(m*3+1,n,count);
}
int main()
{
long long m,n;
int i=0,count=0;
while(1)
{
i++;
scanf("%lld%lld",&m,&n);
if(m<0&&n<0)break;
printf("Case %d: A = %lld, limit = %lld,",i,m,n);
printf("number of terms =%d\n",collatz(m,n,count));
}
return 0;
}
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=635
相关文章推荐
- uva694 The Collatz Sequence
- UVa 694 The Collatz Sequence (数论)
- UVa 694 - The Collatz Sequence
- UVa 694 The Collatz Sequence(序列)
- 694 - The Collatz Sequence
- UVaOJ 694 - The Collatz Sequence
- UVA 694 - The Collatz Sequence
- uva694 The Collatz Sequence
- UVA 694 - The Collatz Sequence
- UVaOJ 694 The Collatz Sequence
- UVA - 694 The Collatz Sequence(水题)
- 694 - The Collatz Sequence
- UVa694 - The Collatz Sequence(模拟)
- uva694 The Collatz Sequence
- uva 694 - The Collatz Sequence
- UVA 694 The Collatz Sequence
- UVA 694-The Collatz Sequence
- uva-694 - The Collatz Sequence
- UVA694 UVALive5466 The Collatz Sequence【模拟】
- UVA694 - The Collatz Sequence