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. html5拨打电话及发短信

    1.最常用WEB页面一键拨号的电话拨打功能 <a href="tel:15088888888">拨号</a> 2.最常用WEB页面一键发送短信功能: < ...

  2. Redis学习和应用记录(1)--介绍和安装

    Redis是一个开源的分布式缓存框架,它也常被理解为数据结构服务器,因为它包含丰富的数据类型,如strings, hashes, lists, sets, sorted sets, bitmaps a ...

  3. [NOI1999] 棋盘分割(推式子+dp)

    http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 156 ...

  4. [Swift通天遁地]二、表格表单-(7)电子邮件Mail:实现单元格左右滑动调出功能按钮

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. JS中的this是什么,this的四种用法

    在Javascript中,this这个关键字可以说是用的非常多,说他简单呢也很简单,说他难呢也很难,有的人开发两三年了,自己好像也说不清this到底是什么.下面我们来看看: 1.在一般函数方法中使用 ...

  6. leetCode----day02---- 买卖股票的最佳时机 II

    要求: 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必 ...

  7. python爬虫之处理验证码

    云打码实现处理验证码 处理验证码,我们需要借助第三方平台来帮我们处理,个人认为云打码处理验证码的准确度还是可以的 首先第一步,我们得先注册一个云打码的账号,普通用户和开发者用户都需要注册一下 然后登陆 ...

  8. ACM_汉诺塔问题(递推dp)

    Problem Description: 最近小G迷上了汉诺塔,他发现n个盘子的汉诺塔问题的最少移动次数是2^n-1,即在移动过程中会产生2^n个系列.由于发生错移产生的系列就增加了,这种错误是放错了 ...

  9. Html学习-File控件学习

    情况一:不设置enctype HTML内容 <form action="02Upload.ashx" method="post"> <inpu ...

  10. HTML中的行级标签和块级标签 《转换》

    1.html中的块级标签 显示为“块”状,浏览器会在其前后显示折行.常用的块级元素包括: <p>, <ul>,<table>,<h1~h6>等. 2.h ...