The Collatz Sequence

原创 2013年12月04日 20:37:59
#include <stdio.h>
int main()
{
    long a, b, i, j = 0, m;
    while(scanf("%ld%ld", &a, &b)!=EOF)
    {
        m = a;
        i = 1;
        if(a < 0 && b < 0) break;
        else
        {
            while(a != 1)
            {
                if(a > b)
                {
                    i--;
                    break;
                }
                else
                {
                if(a % 2 == 0)
                {
                    a = a / 2;
                    i++;
                }
                else
                {
                    a = 3 * a + 1;
                    i++;
                }
                }
            }
        }
        j++;
        printf("Case %ld: A = %ld, limit = %ld, number of terms = %ld\n", j, m, b, i);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

欧拉计划(14)Longest Collatz sequence

【题目】 The following iterative sequence is defined for the set of positive integers: n → n/2 (n ...
  • sgzqc
  • sgzqc
  • 2015-06-19 10:21
  • 315

UVa694 The Collatz Sequence

The Collatz Sequence  An algorithm given by Lothar Collatz produces sequences of intege...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

uvaoj 694 - The Collatz Sequence

/* 刘哥啊 你可把我害惨了啊 你口口声声提醒要用long long 型 我就傻傻的用long long 啊 有木有! C语言%lld要加stdlib 读-1还老出错啊 有木有! c语言过不了再用...

694 - The Collatz Sequence

The Collatz Sequence  An algorithm given by Lothar Collatz produces sequences of integers...

UVA 694 - The Collatz Sequence

刚开始,根据题意, Neither of these, A or L, is larger than 2,147,483,647 (the largest value that can be s...

UVa 694 The Collatz Sequence

The Collatz Sequence  An algorithm given by Lothar Collatz produces sequences of integers...

The Collatz Sequence

Description   The Collatz Sequence  An algorithm given by Lothar Collatz produces sequen...

Problem 14:Longest Collatz sequence

原题链接:http://projecteuler.net/problem=14 The following iterative sequence is defined for the set...

projecteuler---->problem=14----Longest Collatz sequence

title: The following iterative sequence is defined for the set of positive integers: n n/2 (...

UVa 694 The Collatz Sequence(序列)

The Collatz Sequence  An algorithm given by Lothar Collatz produces sequences of integers, and...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)