Last Defence

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

 1 #include <iostream>
 2 using namespace std;
 3 long long a, b, ans;
 4 int nCase, cCase;
 5 long long calc(long long a, long long b)
 6 {
 7     long long ret = 0;
 8     while (b)
 9     {
10         long long t = b;
11         ret += a / b;
12         b = a % b;
13         a = t;
14     }
15     return ret + 1;
16 }
17 int main()
18 {
19     //ios::sync_with_stdio(false);
20     cin >> nCase;
21     while (nCase--)
22     {
23         cin >> a >> b;
24         if (a == 0 && b == 0)
25         {
26             ans = 1;
27         }
28         else if (a == 0 || b == 0)
29         {
30             ans = 2;
31         }
32         else
33         {
34             ans = calc(a, b);
35         }
36         cout << "Case #" << ++cCase << ": " << ans << endl;
37     }
38     return 0;
39 }

 

转载于:https://www.cnblogs.com/Tinamei/p/4864816.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值