Lowest Common Multiple Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30907    Accepted Submission(s): 12528

Problem Description
求n个数的最小公倍数。
 
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
 
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
 
Sample Input
2 4 6
3 2 5 7
 
Sample Output
12
70
 
Author
lcy

解题报告:

先置n个元素最小公倍数为k = 1,然后依次将n个元素与k求最小公倍数,两个两个求。每个将两个元素的最小公倍数与下一个元素继续求最小公倍数。

详细情况见代码。

 #include<stdio.h>

 int func(int m, int n)
{
int i;
if(m > n)
{
int t = m;
m = n;
n = t;
}
for(i = n; ; i++)
{
if(i%m == && i%n==)
break;
}
return i;
}
int main()
{
int n, m;
while(scanf("%d", &n) == )
{
int i, k = ;
for(i = ; i < n; i++)
{
scanf("%d", &m);
k = func(m, k);
}
printf("%d\n", k);
}
return ;
}

HDOJ2028Lowest Common Multiple Plus的更多相关文章

  1. hdoj-2028-Lowest common multiple plus

    题目:Lowest common multiple plus 代码: #include<stdio.h> int common(int a,int b)//计算最大公约数 { int c= ...

  2. K - Least Common Multiple

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

  3. [UCSD白板题] Least Common Multiple

    Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...

  4. hdu1019 Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  5. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  6. 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】

    题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...

  7. HDU-1019 Least Common Multiple

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...

  8. Least Common Multiple

    地址:http://www.codewars.com/kata/5259acb16021e9d8a60010af/train/python 题目: Write a function that calc ...

  9. ACM hdu 1019 Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

随机推荐

  1. Spring Data JPA 教程(翻译)

    写那些数据挖掘之类的博文 写的比较累了,现在翻译一下关于spring data jpa的文章,觉得轻松多了. 翻译正文: 你有木有注意到,使用Java持久化的API的数据访问代码包含了很多不必要的模式 ...

  2. get_template_part() 函数详解备忘(转)

    最近研究官方主题 Twenty Eleven ,有一些东西网上现成的中文资料不好找,在博客里记载下来,算是分享,也算是备忘,wordpress 3.0 以后就开始便有了get_template_par ...

  3. nginx配置ssl

    1.使用pfx证书配置ssl (http://www.heartlifes.com/archives/12/) .上传证书 .生成证书crt及key文件 openssl pkcs12 -in /usr ...

  4. Realsense 提取彩色和深度视频流

    一.简要介绍 关于realsense的介绍,网上很多,这里不再赘述,sdk及相关文档可参考realsense SDK,也可参考开发人员专区. 运行代码之前,要确保你已经安装好了realsense的DC ...

  5. esxi 5.1 由于断电错误无法启动 报错 bank5 invalid configuration

    由于着急,处理过程中也没有截图,这里简单的描写叙述下整个过程吧. IBM pcserver x3850 可能是机器太热的原因,中午无故掉电,导致esxi无法正常启动 启动时报错 bank5 inval ...

  6. Codeforces Round #278 (Div. 1) B. Strip multiset维护DP

    B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...

  7. C# - 函数参数的传递

    近段时间,有几个刚刚开始学习C#语言的爱好者问我:C#中的函数,其参数的传递,按值传递和按引用传递有什么区别.针对这一问题,我简单写了个示例程序,用以讲解,希望我没有把他们绕晕.因为,常听别人说起:“ ...

  8. android140 360 黑名单 启动service和分页加载

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  9. LINUX 运维命令

    查看3306端口被什么程序占用 [root@DB13 ~]# lsof -i : COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME mysqld mysql ...

  10. LINUX 内核文档地址

    Linux的man很强大,该手册分成很多section,使用man时可以指定不同的section来浏览,各个section意义如下: 1 - commands2 - system calls3 - l ...