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