ZOJ 1797 Least Common Multiple

别再写前端了!用Gradio 3.x + HuggingFace Spaces,5分钟把你的Python算法变成网页应用 本文介绍如何利用Gradio 3.x和HuggingFace Spaces快速将Python算法转化为网页应用,无需前端开发经验。通过5行代码和简单的Git命令,即可实现专业级Web界面部署,大幅提升算法展示效率。特别适合算法工程师和数据科学家快速分享模型成果。 阅读详情
Least Common Multiple

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.


Input

Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.


Output

For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.


Sample Input

2
3 5 7 15
6 4 10296 936 1287 792 1


Sample Output

105
10296

题意:求多个数的最大公倍数

思路:最大公约数和最大公倍数的关系,2个数的最大公倍数=2个数相乘/最大公约数

代码:

#include <stdio.h>


long long gcd(long long a,long long b)
{
    long long r;
    while(b!=0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


long long lcd(long long x,long long y,long long z)
{
    return x*y/z;
}


int main()
{
    long long  N,i;
    long long a,b,c,k;
    scanf("%lld",&N);
    while (N--) {
        long long n;
        scanf("%lld",&n);
        if(n==0)
            continue;
        scanf("%lld",&a);
        if(n==1)
        {
            printf("%lld\n",a);
            continue;
        }
        scanf("%lld",&b);
        k=lcd(a,b,gcd(a,b));
        for(i=2;i<n;i++)
        {
            scanf("%lld",&c);
            k=lcd(k,c,gcd(k,c));
        }
        printf("%lld\n",k);
    }
    return 0;
}


WorkBuddy入门到 多Agent团队协作完全指南(附实操代码与配图) WorkBuddy的Agent Teams功能支持多智能体协作,通过创建AI团队提升复杂任务处理效率。该功能支持自然语言创建团队、任务分配与依赖管理、成员间消息通信(包括直接消息和广播),并提供任务审批机制。典型应用场景包括软件开发、内容创作等协作任务。环境要求WorkBuddy 2026年3月及以上版本,支持Windows和macOS系统。用户可快速创建包含不同角色的AI团队,通过共享任务列表和信箱系统实现协作。高级功能包括委派模式、任务依赖管理和成员自主认领等,适合各类协作场景。 阅读详情

相关推荐

机器人动力学仿真软件:V-REP (CoppeliaSim)_(15).仿真项目案例分析

通过以上几个具体的仿真项目案例,我们展示了如何在V-REP (CoppeliaSim)中进行二次开发,实现复杂的机器人动力学仿真任务。这些案例涵盖了六轴机械臂的运动学仿真、移动机器人的路径规划和避障、以及无人机的飞行控制和环境感知。每个项目都通过编写Lua脚本实现了对机器人模型的控制和任务执行,并通过仿真结果分析验证了算法的有效性和系统性能。希望这些案例能够为读者在实际项目中使用V-REP (CoppeliaSim)提供有益的参考和启发。

kkchenjj的博客 1253

zoj 1797 Least Common Multiple(继续,水题,想说爱你不容易!)

<br />求几个数的最小公倍数。。。<br /> <br />这个题,我们大一上学期期末考试考过,当时还不会做 = = YM。。。<br /> <br />求三个数的最小公倍数,直接求前两个数的最小公倍数,然后再和第三个数求最小公倍数,求出即可。<br /> <br />WA得比较YM,因为没考虑n == 1 和 temp == 0 的问题,如果temp == 0 ,就不能当除数了!!<br /> <br />哎。 <br /> <br />gcd算法一次成功,挺有成就感 ^<br /> <br />#i

小媛在努力~ 1885

【CASS精品教程】013:CASS9.1生成标准图幅案例教程

在CASS中,可以很方便的生成标准图幅,如50*50。本文演示cass中,根据测区范围标准图幅生成过程。

智慧空间实验室 1万+

zoj 1797 Least Common Multiple

//求最小公倍数!对输入的数据一对一对的进行求解,再与输入的第三个数据进行求解即可! #include "iostream" #include "algorithm" using namespace std; int main() { int testcase, num, i, j, temp1, temp2, temp3; cin >> testcase; while (testcase

yzl_rex 623

ZOJ - 1797 Least Common Multiple

/* 这道题真的思路一点都不难,我们错了12次,心态炸了。下来后找了半天就是开始使用a*b/(最大公约数)先乘后除的话好像用long long都会溢出,然后找了下题解才知道可以先除后乘就不会越界溢出。 基本思路就是依次依次找最小公倍数。 */ #include<iostream> using namespace std; int lcm(int a,int b) { int ...

一棵小红树 261

zoj1797 Least Common Multiple 最小公倍数

Least Common Multiple Time Limit: 2 Seconds      Memory Limit: 65536 KB The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by a

huadong_fcy56的博客 425

ZOJ Problem Set–1797 Least Common Multiple

Time Limit: 2 Seconds Memory Limit: 65536 KB The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set....

dcl67283的博客 169

ZOJ Problem Set - 1797 Least Common Multiple(最小公倍数)

/*ZOJ Problem Set - 1797Least Common MultipleTime Limit: 1 Second      Memory Limit: 32768 KBThe least common multiple (LCM) of a set of positive integers is the smallest positive integer wh

轻疯 清风 809

数论:zoj 1797 Least Common Multiple

【转】http://blog.csdn.net/zxy_snow/article/details/6011166   #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;iostream&gt; #include &lt;memory.h&gt; #define MAX 10001 using namespa...

caoruntaogmail的博客 125

HDU1019 ZOJ1797 Least Common Multiple【最小公倍数】

Least Common MultipleTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 59471    Accepted Submission(s): 22683Problem DescriptionThe least common m...

海岛Blog 664

ZOJ.1797 Least Common Multiple【最小公倍数,水】 2015/09/22

Least Common Multiple Time Limit: 2 Seconds      Memory Limit: 65536 KB The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by al

>>--» 唯n1.情缘«--<< 416

ZOJ 2172 Symmetric Order

Symmetric Order Time Limit: 2 Seconds      Memory Limit: 65536 KB In your job at Albatross Circus Management (yes, it's run by a bunch of clowns), you have just finished writing a program whose

胖子加油! 1743

ZOJ 1113 u Calculate e

u Calculate e Time Limit: 2 Seconds      Memory Limit: 65536 KB Background A simple mathematical formula for e is where n is allowed to go to infinity. This can actually yield very acc

胖子加油! 1300

ZOJ 1001 A + B Problem

A + B Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB Calculate a + b Input The input will consist of a series of pairs of integers a and b,separated by a space, one pair of inte

胖子加油! 1211

ZOJ 1073 Round and Round We Go

Round and Round We Go Time Limit: 2 Seconds      Memory Limit: 65536 KB Problem A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a ��

胖子加油! 1128

ZOJ 1382 A Simple Task

A Simple Task Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a positive integer n and the odd integer o and the nonnegative integer p such that n = o2^p. Example For n = 24, o = 3

胖子加油! 793

ZOJ 1110 Dick and Jane

Dick and Jane Time Limit: 2 Seconds      Memory Limit: 65536 KB Dick is 12 years old. When we say this, we mean that it is at least twelve and not yet thirteen years since Dick was born. Dick a

胖子加油! 734

ZOJ 1813 Biker's Trip Odometer

Biker's Trip Odometer Time Limit: 2 Seconds      Memory Limit: 65536 KB Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attach

胖子加油! 722

ZOJ 2108 Elevator

Elevator Time Limit: 2 Seconds      Memory Limit: 65536 KB The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which

胖子加油! 659

ZOJ 1871 Steps

Steps Time Limit: 2 Seconds      Memory Limit: 65536 KB One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, o

胖子加油! 654

ZOJ 1334 Basically Speaking

Basically Speaking Time Limit: 2 Seconds      Memory Limit: 65536 KB The Really Neato Calculator Company, Inc. has recently hired your team to help design their Super Neato Model I calculator. A

胖子加油! 653

钣金设计手册(软件版)part1

钣金设计手册(软件版),工程师得力助手,方便钣金用料计算,展开图

自然灾害影像分类数据集,含基础设施破坏、地震、火灾、人体受伤、塌方、洪水等类型的灾害

自然灾害影像分类数据集,影像根据灾难类型被分类到单独的文件夹中,包含基础设施破坏、地震、火灾、人体受伤、塌方、洪水等类型的灾害

上一篇: ZOJ 1796 Euchre Results
下一篇: ZOJ 1813 Biker's Trip Odometer
wpfengqi
博客等级 码龄14年 6粉丝 121原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值