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. 令人惊奇的gdb和pstack

    pstack竟然是一个shell脚本,核心是调用gdb的thread apply all bt查看进程的所有线程的堆栈,之后用sed正则展示线程堆栈信息. /proc/pid/exe是一个指向可执行文 ...

  2. linux之unlink函数解析

    [lingyun@localhost unlink]$ cat unlink.c  /********************************************************* ...

  3. 对PostgreSQL中 pg_各表的RelationId的认识

    读取普通的table或者系统表,都会调用heap_open函数: /* ---------------- * heap_open - open a heap relation by relation ...

  4. 多线程/进度条应用(progressbar)

    使用Control Sets 下的 ProgressBar - Responsive Loop控件 ProcessBar 或者 CancelBar 都可以被设置为 invisible 代码如下(分享自 ...

  5. NAT的全然分析及其UDP穿透的全然解决方式

    NAT的全然分析及其UDP穿透的全然解决方式   一:基本术语 防火墙 防火墙限制了私网与公网的通信,它主要是将(防火墙)觉得未经授权的的包丢弃,防火墙仅仅是检验包的数据,并不改动数据包中的IP地址和 ...

  6. mysql的top n查询

    我们知道,在ms sql server中或access中,若要查询前10条记录,使用top 10即可,但在mysql中不支持这个写法,它用limit 10.  我们可以利用MySQL中SELECT支持 ...

  7. 使用QQ账号的来发送邮件

    第一步,看图操作如下: 打开QQ邮箱,在设置-帐户,然后再看下图示: 把:POP3/SMTP服务,IMAP/SMTP服务,Exchange服务,CardDAV/CalDAV服务都选择上,保存这样,便可 ...

  8. Android 开发之旅:深入分析布局文件&又是“Hello World!”

    http://www.cnblogs.com/skynet/archive/2010/05/20/1740277.html 引言 上篇可以说是一个分水岭,它标志着我们从Android应用程序理论进入实 ...

  9. Swift 3.0 使用Core Data

    swift版本:3.0 Xcode版本:8.0 iOS版本:10.0 自iOS10 和swift3.0 之后,苹果的访问CoreData的方法发生了很大改变,简洁了许多,下面的内容是从0开始建立一个e ...

  10. strcpy_s与strcpy的比較

    strcpy_s和strcpy()函数的功能差点儿是一样的.strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它仅仅能假定缓冲足够大来容纳要拷贝的字符串.在程序执行时,这将 ...