HDOJ 1019 Least Common Multiple
来源:互联网 发布:宁波大学网络课程平台 编辑:程序博客网 时间:2024/05/16 05:11
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
这一题和2028题一样的题,大家可以看看我的2028题
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ int m=sc.nextInt(); int[] a=new int[m]; int sum=1; for(int i=0;i<m;i++){ a[i]=sc.nextInt(); if(sum<a[i]){ sum=a[i]; } } for(int i=0;i<m;i++){ sum=Mu(sum,a[i]); } System.out.println(sum); } } public static int Mu(int x,int y){ for(int i=1;i<=y;i++){ if(((x*i)%y)==0){ x=x*i; break; } } return x; }}
- HDOJ 1019 Least Common Multiple
- HDOJ 1019 Least Common Multiple
- 【HDOJ】1019 -> Least Common Multiple
- HDOJ 1019 Least Common Multiple
- hdoj 1019 Least Common Multiple
- HDOJ Least Common Multiple 1019
- Hdoj 1019 Least Common Multiple
- 【HDOJ】【1019】Least Common Multiple
- HDOJ 1019 Least Common Multiple
- HDOJ 1019 Least Common Multiple
- hdoj 1019Least Common Multiple
- HDOJ 1019 Least Common Multiple
- HDOJ--Least Common Multiple
- hdu/hdoj 1019 Least Common Multiple
- hdoj.1019 Least Common Multiple 20140728
- HDOJ 1019 Least Common Multiple(数学)
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
- hdoj Least Common Multiple【gcd】
- 如何在应用层通过spring特性解决数据库读写分离
- PCM data flow - part 1: Overview
- 50. Pow(x, n)
- Eclipse问题集锦:errors running builder 'Android Pre Compiler' on project'项目名称':java.lang.NullPointerExce
- Ext.net中radiogroup设置选中状态
- HDOJ 1019 Least Common Multiple
- 【bzoj2154】【Crash的数字表格】【莫比乌斯反演】
- Gitlab 创建备份
- Android使用缓存优化ListView
- Tricks(五)—— Python 返回所有符合条件的下标
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- js中对按键的监听
- #include“头文件“的相对路径是相对谁的路径
- 调百度接口,根据地质获取经纬度