Last Defence (2014 西安现场赛)

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94237#problem/K

 

 

Last Defence

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Given two integers A and B. Sequence S is defined as follow:
• S0 = A
• S1 = B
• Si = |Si−1 − Si−2| for i ≥ 2
Count the number of distinct numbers in S.
Input
The first line of the input gives the number of test cases, T. T test cases follow. T is about 100000.
Each test case consists of one line — two space-separated integers A, B. (0 ≤ A, B ≤ 1018).
Output
For each test case, output one line containing ‘Case #x: y’, where x is the test case number (starting
from 1) and y is the number of distinct numbers in S.
Sample Input
2
7 4
3 5
Sample Output
Case #1: 6
Case #2: 5

 

 

#include<stdio.h>

int main()
{
    long long t, iCase=1;
    scanf("%lld", &t);
    while(t--)
    {
        long long a, b, sum=0, k, t;

        scanf("%lld%lld", &a, &b);

        if(a<b)
          t=a, a=b, b=t;

        if(a==0 && b==0)
        {
            printf("Case #%lld: 1\n", iCase++);
            continue;
        }
        else if(b==0)
        {
            printf("Case #%lld: 2\n", iCase++);
            continue;
        }

        while(a%b!=0)
        {
            sum += a/b;
            k = a;
            a = b;
            b = k%b;
        }

        sum += a/b;

        printf("Case #%lld: %lld\n", iCase++, sum+1);
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/YY56/p/4864094.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值