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 <iostream>
using namespace std;
long long a, b, ans;
int nCase, cCase;
long long calc(long long a, long long b)
{
long long ret = ;
while (b)
{
long long t = b;
ret += a / b;
b = a % b;
a = t;
}
return ret + ;
}
int main()
{
//ios::sync_with_stdio(false);
cin >> nCase;
while (nCase--)
{
cin >> a >> b;
if (a == && b == )
{
ans = ;
}
else if (a == || b == )
{
ans = ;
}
else
{
ans = calc(a, b);
}
cout << "Case #" << ++cCase << ": " << ans << endl;
}
return ;
}

最新文章

  1. UGUI&amp;&amp;Animator模块知识点随记
  2. spring.net (3)依赖注入基础
  3. HTML随学随机
  4. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
  5. java 以及 vs 的快捷键
  6. NYOJ 71 独木舟上的旅行(贪心)
  7. A.Alyona and copybooks
  8. XMind 8 pro update 7激活方法
  9. 使用Postfix与Dovecot部署邮件系统
  10. 初步了解Spring
  11. jemter聚合报告参数指标
  12. JS_单个或多个文件上传_不支持单独修改
  13. Spring MVC 注解 @RequestParam解析
  14. C#语言
  15. Python memoryview() 函数
  16. 8张图理解Java---importnew---programcreek
  17. IIS时间格式设置
  18. 高通计划停用MSM 以SDM为移动平台命名【转】
  19. python聚类算法实战详细笔记 (python3.6+(win10、Linux))
  20. html5 +css3 点击后水波纹扩散效果 兼容移动端

热门文章

  1. 软技能-代码外的生存指南PDF下载
  2. [转帖]又一国产x86处理器可大规模上市:Intel至强核心 安全监测管控
  3. [19/05/29-星期三] JavaScript_ 函数的简介
  4. catch that cow POJ 3278 搜索
  5. 解决keil5中文注释乱码方法
  6. django商城项目之用sentry管理日志
  7. HDU 1594 find the max
  8. JS调用PageMethods
  9. 第三方模块:gulp模块
  10. 虚拟机的网卡基本配置和基本linux命令