杭电1019 Least Common Multiple

2024-01-04 02:59

本文主要是介绍杭电1019 Least Common Multiple,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

/********************************
 *    日期:2011-2-9
 *    作者:SJF
 *    题号:杭电1019
 *  题目:Least Common Multiple
 *    结果:AC
 ********************************/
#include<stdio.h>
int LCM(int m,int n)
{
    int dividend;//被除数
    int divisor;//除数
    int r;//余数
    dividend=m;
    divisor=n;
    r=dividend%divisor;
    while(r!=0)
    {
        dividend=divisor;
        divisor=r;
        r=dividend%divisor;
    }
    return m/divisor*n;
}
int main()
{
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        int i,j;
        for(i=0;i<N;i++)
        {
            int M,a,b,result;
            scanf("%d",&M);
            scanf("%d",&b);
            result=LCM(b,1);
            for(j=1;j<M;j++)
            {
                scanf("%d",&a);
                result=LCM(a,result);
            }
            printf("%d\n",result);
        }
    }
    return 0;
}

 

这篇关于杭电1019 Least Common Multiple的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/567962

相关文章

Stripe data files across multiple physical devices and locations

Stripe data files across multiple physical devices and locations 如果在没有做条带的磁盘(即从存储到OS没有做raid),那么就需要手工去做I/O的分布。切记,不应该将频繁使用的table和其index分开,这样会正大I/O; 针对tables、indexes、temp tablespace,首先调优SQL,其次如果真心无法再

兔子--Android Studio出现错误:Error:Execution failed for task ':myapp:dexDebug'. com.android.ide.common.pro

重点在:finished with non-zero exit value 2. 这里表明了有重复的内容存在。 由于:Android Studio中引入包的方式有如下2种:    compile 'com.android.support:support-v4:22.0.0'    compile files('libs/support-v

YOLOV5入门教学-common.py文件

在 YOLOv5 框架中,common.py 文件是一个核心组件,负责定义深度学习模型的基础模块和常用操作。无论是卷积层、激活函数、特征融合还是其他复杂的模型结构,common.py 都提供了灵活且高效的实现。在这篇文章中,我们将深入解析 common.py 的设计思想、各个模块的功能以及它在 YOLOv5 中的应用。通过理解该文件的实现细节,不仅可以帮助我们更好地掌握 YOLOv5 的内部结构,

【ArcGIS Pro实操第二期】最小成本路径(Least-cost path)原理及实操案例

ArcGIS Pro实操第一期:最小成本路径原理及实操案例 概述(Creating the least-cost path)1.1 原理介绍1.2 实现步骤1.3 应用案例 2 GIS实操2.1 工具箱简介2.1.1 成本路径(Cost path)2.1.2 成本距离(Cost distance)2.1.2 路径距离(Path Distance) 2.2 案例: 参考 概述(Cre

【ArcGIS Pro实操第一期】最小成本路径(Least-cost path)原理及实操案例

ArcGIS Pro实操第一期:最小成本路径原理及实操案例 概述(Creating the least-cost path)1.1 原理介绍1.2 实现步骤1.3 应用案例 2 GIS实操2.1 工具箱简介2.1.1 成本路径(Cost path)2.1.2 成本距离(Cost distance)2.1.2 路径距离(Path Distance) 2.2 案例: 参考 概述(Cre

SOMEIP_ETS_088: SD_Answer_multiple_subscribes_together

测试目的: 验证设备(DUT)是否能够接受它接收到的每个SubscribeEventgroup条目。 描述 本测试用例旨在检查DUT在接收到包含多个SubscribeEventgroup条目的消息时,是否能够为每个条目发送SubscribeEventgroupAck。 测试拓扑: 具体步骤: TESTER:发送包含多个SubscribeEventgroup条目的消息,用于事件组:

Page directive: illegal to have multiple occurrences of contentType with different values (x,X)之解

Question: Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html; charset=utf-8, new: text/html;charset=UTF-8) Analysis: 出现这个的原因是这两个jsp的contentT

2024杭电8

1004.cats 的重力拼图 题意: 有一个n*m的矩阵,给出最开始拼图的位置。 可以有四个选择,设置重力的方向,就是拼图会向一个方向竖直掉落到最底。 问任意操作次数后拼图走过的方格数量最大值。 题解: 首先已经在边缘的拼图,只能沿着边走一圈,再判断最开始可以朝哪个方向移动是最大值。 代码: #include<bits/stdc++.h>using namespace s

网络协议栈学习之socket, sock_common, sock, 和 sk_buff

一. 前言   一直很好奇socket是如何实现的,底层的数据结构又是如何,因此在这里对socket的数据结构进行分析。   socket是传输层使用的数据结构,用于声明、定义套接字,网络层会调用sock结构体,其中sock会用到了通用sock_common结构体。而sk_buff则是内核中使用的套接字缓冲区结构体。在我们前文提到的NAT转换中,除了修改内核已有的Netfilter源码外,还有一

Netfilter学习之NAT类型动态配置(八)nf_nat_proto_common.c代码解析

nf_nat_proto_common.c实现了对称型的端口改变,在此我决定对其代码进行分析,以便实现对对称型NAT的随意改动。    具体代码如下: #include <linux/types.h>#include <linux/random.h>#include <linux/netfilter.h>#include <linux/export.h>#include <net/n