Last Defence (2014 西安现场赛)
2024-09-24 06:54:32
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94237#problem/K
Last Defence
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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<stdio.h> int main()
{
long long t, iCase=;
scanf("%lld", &t);
while(t--)
{
long long a, b, sum=, k, t; scanf("%lld%lld", &a, &b); if(a<b)
t=a, a=b, b=t; if(a== && b==)
{
printf("Case #%lld: 1\n", iCase++);
continue;
}
else if(b==)
{
printf("Case #%lld: 2\n", iCase++);
continue;
} while(a%b!=)
{
sum += a/b;
k = a;
a = b;
b = k%b;
} sum += a/b; printf("Case #%lld: %lld\n", iCase++, sum+);
}
return ;
}
最新文章
- 非关系型数据库(NoSql)
- Yii源码阅读笔记(三十一)
- Linux命令 ,在当前目录下查找一个,或者多个文件
- Cookie的使用与实现记住用户名案例
- discuz之搭建
- rsync不存在用户处理CPU消耗拒绝服务漏洞
- 关于Java的this关键字
- 怎么查看mysql执行过的sql。
- 如何使用Ubuntu online account API创建微博HTML5申请书
- 在django中集成ckeditor富文本
- python识别html主要文本框
- DotNetCore跨平台~Moq框架实现模拟测试
- CentOS7安装dnf报错:No package dnf available
- yii2实战之初见端倪
- ubuntu 安装 lamp
- 关于String类学习的一些笔记(本文参考来自程序员考拉的文章)
- Python中的日志处理
- linux screen工具
- OO Summary Ⅲ
- SpringMVC中controller返回图片(转)