PersonalCorpus 版 (精华区)

Your C++ program has solved Ok the problem 694 (The Collatz Sequence)
in 0.460 seconds using as much as 388 kbytes of virtual memory.

void main()
{
    double sa,a,l;
    int sum,tot=0;

    while (scanf("%lf%lf\n",&a,&l)) {
        if ((a<0)&&(l<0)) break;
        sum=1; sa=a;
        while (a!=1) {
            if (a-((int)(a/2))*2<0.25) a=ceil(a/2);
            else { a=3*a+1; if (a>l) break; }
            sum++;
        }
        printf("Case %d: A = %.0lf, limit = %.0lf, number of terms = 
%d\n",++tot,sa,l,sum);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.016毫秒