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
#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的更多相关文章
- 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& ...
- Last Defence (run time error)
Last Defence时间限制:1000 ms | 内存限制:65535 KB描述Given two integers A and B. Sequence S is defined as follo ...
- UVALive 7045 Last Defence
ProblemK. Last Defence Description Given two integersA and B. Sequence S is defined as follow: • S0 ...
- Last Defence (2014 西安现场赛)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94237#problem/K Last Defence Time Limit:3000MS ...
- Unity2D项目-平台、解谜、战斗! 1.2战斗组件Defence、Attack
各位看官老爷们,这里是RuaiRuai工作室,一个做单机游戏的兴趣作坊. 接上文,我们定义了两个分别具有"攻击"和"被攻击"语义的组件CanFight和CanB ...
- CF175E Power Defence
CF175E Power Defence 题意 一个塔防游戏:给定一个无限长的数轴,一个无限血的敌人要从正无穷走到负无穷.你的任务是放置三种塔,包含两种攻击塔和一种寒冰塔,使得敌人受到的伤害最大. 其 ...
- 8.8考试总结(NOIP模拟33)[Hunter·Defence·Connect]
无法逃避的是自我,而无法挽回的是过去. 前言 还算可以,不过 T1 少 \(\bmod\) 了一下挂了 25pts,T2 没看清题面挂了 27pts. 下回注意吧.. T1 Hunter 解题思路 感 ...
- 20210808 Hunter,Defence,Connect
考场 乍一看都不可做 T1 算了半天样例,一直算出来 \(\frac{81}{400}\),直接丢了 T1 推了推发现是求最长连续 \(0\) 的数量,那就是线段树合并加上<玫瑰花精> T ...
- hdu 5779 Tower Defence
题意:考虑由$n$个结点构成的无向图,每条边的长度均为$1$,问有多少种构图方法使得结点$1$与任意其它节点之间的最短距离均不等于$k$(无法到达时距离等于无穷大),输出答案对$1e9+7$取模.$1 ...
- uva 1471 defence lines——yhx
After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...
随机推荐
- Fabric CA/数字证书管理
MSP(Membership Service Provider)成员管理服务提供商 名词: 1.CSR(Cerificate Signing Request):证书签署请求文件 CSR里包含申请者的 ...
- 安装Git并关联
下载git 打开git bash 生成key将 key绑定到帐号 输入命令 ssh-keygen -t rsa -C 'LoginName' 根据命令生成的地址找到对应文件复制密钥 打开github登 ...
- Spring Boot 为什么这么火?(二)
Spring Boot 的火 网上连载了 Spring Boot 系列文章,没想到这一开始便与 Spring Boot 深度结缘. 技术社区 Spring Boot 的文章越来越多:Spring Bo ...
- Java第二周总结
一.Java 基础程序设计 第一章: (1)在Java中源文件的扩展名为.java,编译Java源程序文件产生相应的字节码文件扩展名为.class (2)public class定义要求类名称保持一致 ...
- [转帖]Linux shell中2>&1的含义解释 (全网最全,看完就懂)
Linux shell中2>&1的含义解释 (全网最全,看完就懂) https://blog.csdn.net/zhaominpro/article/details/82630528 ...
- CentOS7 策略路由配置
环境说明:Cloud1中的GE0/0/1.GE0/0/3.GE0/0/5接口,分别与Centos7中的eth1.eth2.eth3接口桥接到同一虚拟网卡,R1,R2,R3均配置一条静态默认路由指向Ce ...
- Dos - 学习总结(1)
1.控制台复制 1>鼠标右键,标记. 2>选定复制内容后,鼠标右键,完成复制. 2.
- java不能卸载,提醒路劲找不到 *:\Java\
安装MyEclipse是提醒找不到java安装路劲 :*:\Java\jdk1.7.0_80 想卸载java重装也没法卸载,还是同样的提醒 找不到java安装路劲 :*:\Java\jdk1.7.0_ ...
- 【NOI2007】项链工厂 ——老题新做.jpg
第一次是用 ODT 过的...(虽说跑得飞慢但它就是能过) 而且还写了发题解... 第二次是在考场上碰到了这道题,然后居然打了线段树,各种 bug 直接让代码爆零 但还是补好了代码重新交了一发,发现跑 ...
- Serilog
参考 asp.net core使用serilog将日志推送到腾讯云日志服务