HDOJ-1920-Jackpot 解题报告

       求多个数的最小公倍数,水题。题意:简单说吧,老虎机有几个转盘,每一个转盘停留在jackpot上都有一个固定的周期,如果所有转盘都停留在jackpot上,那么就可以赢钱,现在要求赢钱的周期,如果大于指定的数就要给出指定的信息。


       我的解题思路:每个转盘的周期求最小公倍数就可以了,考虑一下边界情况只有一个转盘的情况就行了,另外根据题意如果最小公倍数大于10^9的话就输出“More than a billion.就好了。


       我的解题代码:

#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long Long;

const Long N = 5;
const Long M = 10e9;

Long num[N];
Long ans;
int t, n;

Long Gcd(Long a, Long b);

Long Lcm(Long a, Long b);

int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        for (int i=0; i<n; ++i)
        {
            scanf("%lld", &num[i]);
        }
        ans = num[0];
        for (int i=1; i<n; ++i) ans = Lcm(ans, num[i]);
        if (ans <= M)
            printf("%lld\n", ans);
        else
            puts("More than a billion.");
    }
    return 0;
}

Long Gcd(Long a, Long b)
{
    return b == 0 ? a : Gcd(b, a % b);
}

Long Lcm(Long a, Long b)
{
    return a / Gcd(a, b) * b;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值