BestCoder Round #75 1001模拟

King's Cake

 
 Accepts: 960
 
 Submissions: 1572
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
阅兵式前一天,是国王的生日,大臣们为他准备了一个 n \times m(1\le n, m \le 10000)n×m(1n,m10000) 的蛋糕。他准备切蛋糕,但他切蛋糕有奇奇怪怪的癖好,他每次只切一刀,切下一个正方形蛋糕。请问它最多能切出多少个正方形蛋糕?
输入描述
第一行一个整数表示测试组数:T(0 < T\le1000)T(0<T1000) 。

每组数据占一行,每行两个整数 n \times m(1\le n, m \le 10000)n×m(1n,m10000),表示蛋糕的大小。
输出描述
TT 行,每行一个整数表示最多能切出的正方形蛋糕数量。
输入样例
2
2 3
2 5
输出样例
3
4
Hint
对于第一组数据,可切出一个 2\times22×2, 两个 1\times 11×1,共 33 个。

对于第一组数据,可切出两个 2\times22×2, 两个 1\times 11×1,共 44 个。
题解:直接模拟
代码:
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
#ifdef CDZSC_June
    freopen("t.txt","r",stdin);
#endif //CDZSC_June
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        int sum = 0,p,k;
        scanf("%d%d",&n,&m);
        if(n == m){
            puts("1");
        }
        else
        {
            int max1 = max(n,m), min1 = min(n,m);
            while(min1>=1)
            {
                sum += max1/min1;
                p = max1,k = min1;
                max1 = max(p%k,k);
                min1 = min(p%k,k);
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值