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 ...
随机推荐
- linux/linux学习笔记-常用命令(mooc)
一.命令基本格式及文件处理命令 1.linux命令格式 简化选项用-表示,完整选项用--表示 注:linux通过权限位第1位(-:文件 / d:目录 / l:链接文件 来区分文件类型) 2.linux ...
- [DS+Algo] 004 栈、队列及其代码实现
1. Stack FILO (FirstInLastOut) 的链表结构 在程序编译环境上使用较多 常用操作 push pop peek is_empty size Python 代码示例 class ...
- 一个简单的Vue.js组件开发示例
//创建属于自己的vue组件库 (function(Vue, undefined) { Vue.component("my-component", { template: '< ...
- letsencrypt 免费SSL证书申请, 自动更新
Let's Encrypt 泛域名 证书申请 及自动更新 关键字:SSL证书.HTTPS 初次申请 1. 下载certbot wget https://dl.eff.org/certbot-auto ...
- Linux安装Jenkins并部署springboot项目
安装步骤: 1.跳转连接https://pkg.jenkins.io/redhat-stable/下载安装包 2.安装命令: sudo rpm -ih jenkins-2.73.2-1.1.noarc ...
- 基于Red5与ffmpeg实现rtmp处理NVR或摄像头的监控视频处理方案
背景 各大监控视频平台厂商与外对接均是基于IE的OCX插件方式提供实时视频查看.历史视频回放与历史视频下载.在h5已大行其道的当下,基于IE的OCX插件方式已满足不了广大客户的实际需求,因此需要一个兼 ...
- django基础篇02-url路由系统
django的路由系统: 一.基本用法: 1.path('index', views.index), # 通过类的方式创建url映射 2.path('home', views.Home.as_view ...
- Vue之路由跳转 传参 aixos 和cookie
一.路由跳转 1.1 项目的初始化 vue create m-proj >>>创建vue项目 精简vue项目的 views 视图 About(基本是删除的) Home.(可以 ...
- github配置及使用
安装git 对于linux系统,不同发行版本的安装方法不一样,请参考https://git-scm.com/download/linux.以ubuntu为例: sudo add-apt-reposit ...
- CentOS 7 环境下部署 SVN 并实现自动更新(版本库放在Tomcat下)
1.安装 SVN 1.1先检查是否有安装 svn rpm -qa subversion #没有什么显示就说明没有安装过yum remove subversion #如果有安装就运行删除老版本yum i ...