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

  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. long long t, iCase=;
  6. scanf("%lld", &t);
  7. while(t--)
  8. {
  9. long long a, b, sum=, k, t;
  10.  
  11. scanf("%lld%lld", &a, &b);
  12.  
  13. if(a<b)
  14. t=a, a=b, b=t;
  15.  
  16. if(a== && b==)
  17. {
  18. printf("Case #%lld: 1\n", iCase++);
  19. continue;
  20. }
  21. else if(b==)
  22. {
  23. printf("Case #%lld: 2\n", iCase++);
  24. continue;
  25. }
  26.  
  27. while(a%b!=)
  28. {
  29. sum += a/b;
  30. k = a;
  31. a = b;
  32. b = k%b;
  33. }
  34.  
  35. sum += a/b;
  36.  
  37. printf("Case #%lld: %lld\n", iCase++, sum+);
  38. }
  39. return ;
  40. }

Last Defence (2014 西安现场赛)的更多相关文章

  1. 2014西安现场赛F题 UVALA 7040

    地址 题意:求在m种颜色中挑选k种颜色,给n个花朵涂色有几种方法. 分析:画图可以发现,基本的公式就是k ×(k-1)^(n-1).但这仅保证了相邻颜色不同,总颜色数不超过k种,并没有保证恰好出现k种 ...

  2. CF GYM100548 (相邻格子颜色不同的方案数 2014西安现场赛F题 容斥原理)

    n个格子排成一行,有m种颜色,问用恰好k种颜色进行染色,使得相邻格子颜色不同的方案数. integers n, m, k (1 ≤n, m ≤ 10^9, 1 ≤ k ≤ 10^6, k ≤ n, m ...

  3. 2020 ICPC EC Final西安现场赛游记

    也不知道从何说起,也不知道会说些什么,最想表达的就是很累很累. 从第一天去的时候满怀希望,没什么感觉甚至还有一些兴奋.到后来一直在赶路,感觉很疲惫,热身赛的时候觉得马马虎虎,导致热身赛被咕.然后教练就 ...

  4. hdu 5078 2014鞍山现场赛 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...

  5. hdu 5073 Galaxy(2014 鞍山现场赛)

    Galaxy                                                                   Time Limit: 2000/1000 MS (J ...

  6. hdu 5071(2014鞍山现场赛B题,大模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...

  7. zoj 3820(2014牡丹江现场赛B题)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5374 思路:题目的意思是求树上的两点,使得树上其余的点到其中一个点的 ...

  8. 2014 牡丹江现场赛 A.Average Score(zoj 3819) 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 题目意思: 有两个class:A 和 B,Bob 在 Clas ...

  9. 2014 牡丹江现场赛 i题 (zoj 3827 Information Entropy)

    I - Information Entropy Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %l ...

随机推荐

  1. UNION会自动删除重复项,union与union all的差异

    UNION会自动删除重复项,刷选出部分字段的时候要注意了,如果刷选出来的两个字段的值完全相同就会剩下一个. UNION ALL 和 UNION 不同之处在于 UNION ALL 会将左右两个查询的结果 ...

  2. Haskell语言学习笔记(51)Comonad

    Comonad class Functor w => Comonad w where extract :: w a -> a duplicate :: w a -> w (w a) ...

  3. Java Magic. Part 4: sun.misc.Unsafe

    Java Magic. Part 4: sun.misc.Unsafe @(Base)[JDK, Unsafe, magic, 黑魔法] 转载请写明:原文地址 系列文章: -Java Magic. P ...

  4. tf.Session()、tf.InteractiveSession()

    tf.Session()和tf.InteractiveSession()的区别 官方tutorial是这么说的: The only difference with a regular Session ...

  5. SSH框架整合思想

    --------------------siwuxie095                                 SSH 框架整合思想         1.SSH 框架,即 Struts2 ...

  6. day8:vcp考试

    Q141. An administrator is unable to upgrade a vCenter Server Appliance from version 5.1 Update 2 to ...

  7. mybatis sql语句符号问题

    写sql语句<或>不能直接写,而应写作<或>,不然项目不能正常编译启动

  8. 在ecplise中创建一个maven工程

    1.我们首先需要在Ecplise中配置maven环境,详情见我的博客:https://www.cnblogs.com/wyhluckdog/p/10277278.html 2.maven projec ...

  9. linq to sql之like

    contains——like '%提交%' StartsWith—— like '条件%' EndWith——like '%条件'

  10. 使用PHP-GTK编写一个windows桌面应用程序

    PHP-GTK的下载地址:http://gtk.php.net/download.php?language=en-US, 猿哥选择了最新版本(beta版),可能有人会问我们为啥不选最新的stable版 ...