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 ...
随机推荐
- 第三章 四大组件之Activity(一)生命周期
1.生命周期: onCreate()->onStart()->onResume()->onPause()->onStop()->onDestroy() 2.各种状况下Ac ...
- TypeScript ES6-Promise 递归遍历文件夹中的文件
貌似很多人都爱用这个作为写文章的初尝试,那来吧.遍历文件夹下的所有文件,如遍历文件夹下并操作HTML/CSS/JS/PNG/JPG步骤如下:1.传入一个路径,读取路径里面所有的文件:2.遍历读取的文件 ...
- 2、Java调用C语言(JNative法)
这个方法也是挺麻烦的…… 一.下载JNative.jar,把它放在你jdk下的\jre\lib\ext目录下 二.在 F:\MinGW\JNative 新建 Test.java: public cla ...
- B/S,C/S架构的区别
B/S架构:browser/server,采用的是浏览器服务器模式. C/S架构:client/server,采用的是客户端服务器模式. B/S架构,客户端是浏览器基本不需要维护,只需要维护升级服务器 ...
- 2018 Web 开发者路线图[转载]
2018 Web 开发者路线图[转载] https://qianduan.group/posts/5a66f36e0cf6b624d2239c74?hmsr=toutiao.io&utm_me ...
- netdevice - 底层访问 Linux 网络设备
总览 (SYNOPSIS) #include <sys/ioctl.h> #include <net/if.h> 描述 (DESCRIPTION) 本手册 描述 用于 配置 网 ...
- quartus ip核破解
在证书文件中添加一段: FEATURE 6AF7_0012 alterad 2035.12 permanent uncounted E75BE809707E VENDOR_STRING="i ...
- Zabbix--02 自定义监控主机
目录 一. Zabbix 监控基础架构 二. zabbix 快速监控主机 1.安装zabbix-agent 2.配置zabbix-agent 3.启动zabbix-agent并检查 4.zabbix- ...
- 使ApacheBench支持multi-url
目录 1.下载Apache httpd相关源码包以及针对ab工具的patch包 2.编译安装apr 3.编译安装apr-util 4.替换httpd源码里面的ab.c文件 5.编译安装httpd 6. ...
- css3 transform中的matrix矩阵
CSS3中的矩阵CSS3中的矩阵指的是一个方法,书写为matrix()和matrix3d(),前者是元素2D平面的移动变换(transform),后者则是3D变换.2D变换矩阵为3*3, 如上面矩阵示 ...