zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    Block深入浅出
    JSPatch 遇上swift
    iPhone左下角app图标
    Handoff使用指南
    实习任务——导出excel
    实习任务——对查询结果进行筛选过滤
    Markdown基本语法
    学习笔记(二)——类加载及执行顺序
    #学习笔记(一)——static
    写给过去的3年,拥抱2016
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4864816.html
Copyright © 2011-2022 走看看