编程介的小学生 2017-04-21 02:54 采纳率: 20.5%
浏览 845
已采纳

Arnie's Dog Biscuits

Our discerning gourmet puppy Arnie is turning to you for a program to help him split his dog biscuits. Each biscuit is shaped like a rectangle and perforated into equal sized squares:

Unfortunately, Arnie will only eat square-shaped biscuits; therefore, he must break the biscuit into squares. Each break, termed a split, is applied to one rectangle, runs along one straight perforated line, and separates the rectangle into two pieces:

Input

The first line of the input contains one positive integer n, the number of biscuits to split. Each of the next n lines contains two positive integers r and c, the number of rows and columns of one biscuit, separated by white space.

Output

The output contains one line for each biscuit specifying the minimal number of splits required to break the biscuit into squares.

Sample Input

2
6 7
5 5
This defines two biscuits: the one shown above which requires four splits, and a square biscuit which requires no splits.

Sample Output

4
0

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?