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

最新文章

  1. 非关系型数据库(NoSql)
  2. Yii源码阅读笔记(三十一)
  3. Linux命令 ,在当前目录下查找一个,或者多个文件
  4. Cookie的使用与实现记住用户名案例
  5. discuz之搭建
  6. rsync不存在用户处理CPU消耗拒绝服务漏洞
  7. 关于Java的this关键字
  8. 怎么查看mysql执行过的sql。
  9. 如何使用Ubuntu online account API创建微博HTML5申请书
  10. 在django中集成ckeditor富文本
  11. python识别html主要文本框
  12. DotNetCore跨平台~Moq框架实现模拟测试
  13. CentOS7安装dnf报错:No package dnf available
  14. yii2实战之初见端倪
  15. ubuntu 安装 lamp
  16. 关于String类学习的一些笔记(本文参考来自程序员考拉的文章)
  17. Python中的日志处理
  18. linux screen工具
  19. OO Summary Ⅲ
  20. SpringMVC中controller返回图片(转)

热门文章

  1. cprogram作业
  2. ArcGIS案例学习笔记2_2
  3. python集合的交,差,并,补集合运算汇总
  4. in 和 exist 区别 (转)
  5. Spark之 Spark Streaming整合kafka(Java实现版本)
  6. Hibernate 序列生成主键
  7. ORDER BY 子句在视 图、内联函数、派生表、子查询和公用表表达式中无效
  8. Fragment 生命周期 全局变量的声明位置
  9. php不重新编译,安装未安装过的扩展,如curl扩展
  10. HHVM中文网