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 ;
}

Last Defence的更多相关文章

  1. Dedecms include\dialog\select_soft_post.php Upload Any Files To The Specified Directory Via Variable Not Initial Flaw Bypass Extension Defence

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 综合来说,这个漏洞的根源是"register_globals = on& ...

  2. Last Defence (run time error)

    Last Defence时间限制:1000 ms | 内存限制:65535 KB描述Given two integers A and B. Sequence S is defined as follo ...

  3. UVALive 7045 Last Defence

    ProblemK. Last Defence Description Given two integersA and B. Sequence S is defined as follow: • S0 ...

  4. Last Defence (2014 西安现场赛)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94237#problem/K Last Defence Time Limit:3000MS ...

  5. Unity2D项目-平台、解谜、战斗! 1.2战斗组件Defence、Attack

    各位看官老爷们,这里是RuaiRuai工作室,一个做单机游戏的兴趣作坊. 接上文,我们定义了两个分别具有"攻击"和"被攻击"语义的组件CanFight和CanB ...

  6. CF175E Power Defence

    CF175E Power Defence 题意 一个塔防游戏:给定一个无限长的数轴,一个无限血的敌人要从正无穷走到负无穷.你的任务是放置三种塔,包含两种攻击塔和一种寒冰塔,使得敌人受到的伤害最大. 其 ...

  7. 8.8考试总结(NOIP模拟33)[Hunter·Defence·Connect]

    无法逃避的是自我,而无法挽回的是过去. 前言 还算可以,不过 T1 少 \(\bmod\) 了一下挂了 25pts,T2 没看清题面挂了 27pts. 下回注意吧.. T1 Hunter 解题思路 感 ...

  8. 20210808 Hunter,Defence,Connect

    考场 乍一看都不可做 T1 算了半天样例,一直算出来 \(\frac{81}{400}\),直接丢了 T1 推了推发现是求最长连续 \(0\) 的数量,那就是线段树合并加上<玫瑰花精> T ...

  9. hdu 5779 Tower Defence

    题意:考虑由$n$个结点构成的无向图,每条边的长度均为$1$,问有多少种构图方法使得结点$1$与任意其它节点之间的最短距离均不等于$k$(无法到达时距离等于无穷大),输出答案对$1e9+7$取模.$1 ...

  10. uva 1471 defence lines——yhx

    After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...

随机推荐

  1. C语言中,当计算字符数组长度时,用sizeof 和strlen 的原理及两者的区别

    字符数组的长度计算:必须以终止符’\0'作为边界,但对字符数组赋值时,有两种方式: 1:定义时用字符初始化 (1)char chs[7] = {'a', 'c', '0', 'z', '3','d'} ...

  2. ant buid.xml 模板

    <?xml version="1.0" encoding="UTF-8"?> <project name="ant" de ...

  3. SparkStreaming DStream转换

    1.无状态转换操作 (1)无状态转化操作就是把简单的RDD转化操作应用到每个批次上,也就是转换DStream中的每一个RDD. 部分无状态转化操作: (2)尽管这些函数韩起来像作用在整个流上一样,但事 ...

  4. thinkPHP三级城市联动

    html+js: <!doctype html> <html lang="en"> <head> <meta charset=" ...

  5. python 发送kafka

    python 发送kafka大体有三种方式 1 发送并忘记(不关注是否正常到达,不对返回结果做处理) 1 import pickle 2 import time 3 from kafka import ...

  6. Prometheus 2.14.0 新特性

    Prometheus 2.14.0 现在(2019.11.11)已经发布,在上个月的 2.13.0 之后又进行了一些修正和改进. 这次最大的新功能是基于 React 的新 UI,与现有 UI 大体相同 ...

  7. 关于websocket 在生产环境中遇到的问题 及 解决办法

    一  生产环境说明 1) tornado 4.2 2) Tornado-MySQL 3) supervisor 3.0b2 4) protobuf 2.6.1 5) python 2.7.6 6) n ...

  8. unittest加载用例

    diascover加载测试用例 1.discover方法里面有三个参数: -case_dir:这个是待执行用例的目录. -pattern:这个是匹配脚本名称的规则,test*.py意思是匹配test开 ...

  9. c# wpf 加密文本

    可以加密人们的内容,文本加密. 界面 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation& ...

  10. linux Apache 日志配置

    [root@Nagios-Server extra]# vimhttpd-vhosts.conf <VirtualHost *:80> ServerAdmin 111111 ServerN ...