hdu 1019 Least Common Multiple

简介: hdu 1019 Least Common Multiple

Problem Description

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

 

就是求最小公倍数

 

代码:

#include<stdio.h>
int a[10000];
int MAX(int n)
{
int i,max=0;
for(i=0;i<n;i++)
if(max<a[i])
max=a[i];
return max;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int i,j,s=1,f=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=2;i<=MAX(n);i++)
{
//    printf("max=%d\n",MAX(n));
for(j=0;j<n;j++)
if(a[j]%i==0) {a[j]/=i;f=1;}
if(f==1) {s*=i;i=1;}
f=0;
}
printf("%d\n",s);
}
return 0;
}
目录
相关文章
|
8月前
|
存储 算法 安全
新增密级管理能力,筑牢数据安全合规防线——基于阿里云密评合规框架的专业实践
本文以某制造企业8000万元数据泄露事件为引,揭示“全员可见”的粗放加密之弊,强调密级管理才是数据安全核心。通过对比传统加密与密级管理差异,剖析越权访问、密钥连锁泄露等风险,并介绍阿里云KMS、CloudHSM、RAM及国密算法四大能力,详解第三方软件如何实现密级标签映射、权限分级绑定与合规审计闭环,助力企业满足等保2.0、密评及《数据安全法》要求。(239字)
|
自然语言处理 网络架构 索引
Elasticsearch7.1之cerebro使用(一)
Elasticsearch7.1之cerebro使用(一)
411 1
|
SQL 安全 网络安全
[网络安全]sqli-labs Less-4 解题详析
判断注入类型 GET1" and "1"="1,回显如下
259 0
[网络安全]sqli-labs Less-4 解题详析
|
存储 缓存 固态存储
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8083 2
|
12天前
|
域名解析 人工智能 Linux
|
20天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10361 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
5天前
|
人工智能 安全 网络安全