Least Common Multiple

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

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
 
Source
 
题意:求几个数的最小公倍数
思路:前两个数求一次,求得的结果再与下一个数求
 
 //hdu_1019_Least Common Multiple_201310290920-2
#include <stdio.h>
#include <malloc.h> void swap(int* a,int* b)
{
int t;
t=*a;
*a=*b;
*b=t;
}
int gcd(int m,int n)
{
int i;
if(m>n)
swap(&m,&n);
i=m;
while(i)
{
i=n%m;
n=m;
m=i;
}
return n;
}
int main()
{
int N;
scanf("%d",&N);
while(N--)
{
int i,j,n,t;
int *shuzu;
scanf("%d",&n);
shuzu = (int*)malloc(sizeof(int)*n);
for(i=;i<n;i++)
scanf("%d",&shuzu[i]);
for(i=;i<n-;i++)
{
t=gcd(shuzu[i],shuzu[i+]);
shuzu[i+]=shuzu[i]/t*shuzu[i+];
//shuzu[i+1]=shuzu[i]*shuzu[i+1]/t;这样容易造成数据溢出
}
printf("%d\n",shuzu[n-]);
free(shuzu);
}
//printf("%d\n",gcd(5,15));
//while(1);
return ;
}
//ac
 #include <stdio.h>
#include <malloc.h> int main()
{
int N;
scanf("%d",&N);
while(N--)
{
int i,j,n;
int *shuzu;
scanf("%d",&n);
shuzu = (int*)malloc(sizeof(int)*n);
for(i=;i<n;i++)
scanf("%d",&shuzu[i]);
for(i=;i<n-;i++)
for(j=shuzu[i];j<=shuzu[i]*shuzu[i+];j++)
if(j%shuzu[i]==&&j%shuzu[i+]==)
{
shuzu[i+]=j;
break;
}
printf("%d\n",shuzu[n-]);
free(shuzu);
}
return ;
}
//TML
 

hdu_1019_Least Common Multiple_201310290920的更多相关文章

  1. Socket聊天程序——Common

    写在前面: 上一篇记录了Socket聊天程序的客户端设计,为了记录的完整性,这里还是将Socket聊天的最后一个模块--Common模块记录一下.Common的设计如下: 功能说明: Common模块 ...

  2. angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)

    common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...

  3. Common Bugs in C Programming

    There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...

  4. ANSI Common Lisp Practice - My Answers - Chatper - 3

    Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...

  5. [LeetCode] Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  6. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  7. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  8. 48. 二叉树两结点的最低共同父结点(3种变种情况)[Get lowest common ancestor of binary tree]

    [题目] 输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点. 二叉树的结点定义如下:  C++ Code  123456   struct BinaryTreeNode {     int ...

  9. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

随机推荐

  1. localStorage 读&&写

    localStorage.setItem('edit',nowedit);  写 var nowedit1= localStorage.getItem('editdel');读

  2. 1章 课程介绍 IDEA介绍演示与安装 IDEA安装

  3. zabbix监控kafka消费

    一.Kafka监控的几个指标 1.lag:多少消息没有消费 lag=logsize-offset 2.logsize:Kafka存的消息总数 3.offset:已经消费的消息 Kafka管理工具 介绍 ...

  4. 浅析SpringDataJpa继承结构

    一.SpringDataJpa的含义: SpringDataJpa: 是Spring基于ORM框架.JPA规范封装的一套JPA应用框架,是SpringData中的一个子模块,可让开发者用极简的代码即可 ...

  5. quill支持json吗

    RT quill目前的驱动(2.4.2版本)不支持json,等待作者更新版本吧

  6. MyBatis Generator实现MySQL分页插件

    MyBatis Generator是一个非常方便的代码生成工具,它能够根据表结构生成CRUD代码,可以满足大部分需求.但是唯一让人不爽的是,生成的代码中的数据库查询没有分页功能.本文介绍如何让MyBa ...

  7. Spring实例化bean之后的处理, 关于BeanPostProcessor接口的使用

    业务需求:缓存页面,展示需要缓存的所有对象,每类对象在字典表中有编码对应,点击某个对象可以缓存某类对象,每类对象都有自己的缓存runner(弱弱的说一句,本人看到这里的第一反应就是if-else,捂脸 ...

  8. Idea使用Maven搭建SpringMVC的HelloSpringMvc并配置插件Maven和Jetty

    这篇博文只是纯粹的搭建一个SpringMVC的项目, 并不会涉及里面配置文件该写些什么. 只是纯粹的搭建一个初始的Hello SpringMVC的项目. 废话不多说,上图. 1.  打开IDEA 并且 ...

  9. Codeforces 19E 树上差分

    思路: 先随便建出来一棵搜索树(图可能不连通?) 每一条非树边(剩下的边)和树边都可以构成一个环. 我们只看一个非树边和某些树边构成的这些环. 分成三种情况: 1.没有奇环  所有边都可以删 2.有一 ...

  10. “国家队爷”杯液体战争AI比赛!!__SymenYang

    原帖 这两天一直在搞这个AI,提供的样例更本不是我的风格啊,看不懂更不会改... 所以我自己写了一个AI的平台,现在在不断的修改AI的策略,smart样例还是很容易过的,让line的行走速度变慢一点到 ...