We all know about the legend of tower of Hanoi. It is said that the world will end after finishing the puzzle. What we don’t know is another legend about when the world will end which is verified by the scientists.
    It is all about a 3n ∗ 3m grid. Initially the grid is filled with 1 to 3(m+n) in row major order. At each step the puzzle is rearranged by reading it in row major order and putting them in collumn major order. See the following examples.

    Now every day the puzzle is rearranged once. The legend says if someday initial configuration returns the world will end. Now you are wondering when the world is going to end.
Input
Input starts with a line containing number of test cases T ≤ 10000. Each test case contains two positive integer m ≤ 109 and n ≤ 109.
Output
For each case print one line containing days before dooms day. The input will be such that this number fits in 64 bit unsigned integer.
Sample Input
5
1 1
1 2
3 1
2 2
98876767 12234
Sample Output
Case 1: 2
Case 2: 3
Case 3: 4
Case 4: 2
Case 5: 98889001

问题链接:UVA11774 Doom’s Day
问题简述:(略)
问题分析:这个题的关键是找出数学规律,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11774 Doom's Day */#include <bits/stdc++.h>using namespace std;int main()
{int t;scanf("%d", &t);for(int k = 1; k <= t; k++) {long long m, n;scanf("%lld%lld", &m, &n);printf("Case %d: %lld\n", k, (m + n) / __gcd(m, n));}return 0;
}

UVA11774 Doom‘s Day【数学规律+GCD】相关推荐

  1. GCD XOR UVA - 12716 ——筛法建立约数表+xor运算+数学规律

    Think: 1埃式筛法思想建立约数表 2初始打表寻找运算的数学规律 3xor运算(不带进位的二进制加法) 运算法则 1. a ⊕ a = 0 2. a ⊕ b = b ⊕ a 3. a ⊕b ⊕ c ...

  2. 【LeetCode】﹝数学规律ி﹞第N位数字、可怜的小猪

    [LeetCode]﹝数学规律ி﹞第N位数字.可怜的小猪 文章目录 [LeetCode]﹝数学规律ி﹞第N位数字.可怜的小猪 乐团站位★ 罗马数字转整数★ 整数转罗马数字★★ 第 N 位数字★★ 数字 ...

  3. 【算法学习笔记】73.数学规律题 SJTU OJ 1058 小M的机器人

    Description 小M有很多个机器人,他们要么一直说真话,要么一直说假话. 然后每个人都说: (1). 不到N个人比我工作得多 (2). 至少M个人的工资比我高. 保证没有两个人的工作一样重,也 ...

  4. UVA10162 Last Digit【数学规律】

    Give you a integer number N (1 ≤ n ≤ 2 ∗ 10100). Please compute S = 11 + 22 + 33 + . . . + NN Give t ...

  5. UVA10025 The ? 1 ? 2 ? ... ? n = k problem【数学规律】

    Given the following formula, one can set operators '+' or '-' instead of each '?', in order to obtai ...

  6. 用Python解中考数学规律题

    用Python解中考数学规律题 以下为2018成都市的中考数学真题B卷第23题: 分析:   一.这是一道常规的找规律考题,一般每年的中考数学都会涉及,根据题的难易程度,位置一般会出现在B卷的第二题, ...

  7. 1235813找规律第100个数_2018年中考数学规律探索题(中考找规律题目-有答案)

    <2018年中考数学规律探索题(中考找规律题目-有答案)>由会员分享,可在线阅读,更多相关<2018年中考数学规律探索题(中考找规律题目-有答案)(16页珍藏版)>请在金锄头文 ...

  8. 快乐数之数学规律解题

    数学规律解决快乐数 题目 编写一个算法来判断一个数 n 是不是快乐数. 「快乐数」定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这 个过程直到这个数变为 1,也可能是 ...

  9. 【leetcode-Python】-找数学规律-LCP 29. 乐团站位

    题目链接 https://leetcode-cn.com/problems/SNJvJP/ 题目描述 某乐团的演出场地可视作 num * num 的二维矩阵 grid(左上角坐标为 [0,0]),每个 ...

最新文章

  1. 浏览器生成消息-探索浏览器的内部(1)
  2. linux 模块常用命令
  3. DataInputStream
  4. C# XML 添加,修改,删除Xml节点
  5. 以HANA为核心 SAP实时数据平台详解
  6. 不该失去的,一块钱也不放弃
  7. sysadmin默认密码_Sysadmin指南,开源电子邮件客户端,macOS应用程序,SELinux,Firefox扩展等...
  8. layui upload.render上传组件js动态添加html后再次渲染
  9. 软件技术方案_智慧工地整体解决方案核心系统有哪些?
  10. Ubuntu通过apt安装LAMP环境
  11. 无法启动程序因为计算机中丢失dev,DevUseAnalyzerTask.dll
  12. FFmpeg 视频添加水印
  13. Linux pthread详解
  14. 视界云联合创始人姜飞 荣获品途2017年NBI商业影响力新锐人物奖
  15. 01百思不得其姐基本配置
  16. java简单识别闰年和平年问题
  17. ITest:京东数科接口自动化测试实践
  18. 云服务器的回收站在哪个文件夹,云主机无法从回收站删除解决办法
  19. 瞬态抑制二极管TVS的基本知识
  20. sharemouse切窗口就锁定了什么原因_使各大网课软件监控功能和锁定功能“失效”...

热门文章

  1. gradle——eclipse中安装与web项目创建
  2. 浅谈格斗游戏的精髓——方块的战争
  3. Zend Framework 简介
  4. 以用户为中心的SNS站点数据库设计及实现
  5. python 自动登录方法_Python实现自动登录百度空间的方法
  6. itext根据数据生成PDF
  7. HTTP请求报文分析
  8. Ubuntu中切换用户
  9. 在access窗体中加图片_如何在Access窗体中显示指定路径的图片
  10. python 中decorator和property