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. struts2里result类型Stream的参数配置

    转自:https://blog.csdn.net/q714699280/article/details/51756126 contentType 内容类型,和互联网MIME标准中的规定类型一致,例如t ...

  2. CSS小代码汇总整理

    /**实现斑马线的表格*/table.flexme tbody tr:nth-child(2n){background-color:#D6E7FC;} /*返回偶数序的子元素*/table.flexm ...

  3. 虚拟化技术概要之VMM结构

    1. 概述 当前主流的 VMM (Virtual Machine Monitor) 实现结构可以分为三类: 宿主模型 (OS-hosted VMMs)Hypervisor 模型 (Hypervisor ...

  4. PCB genesis孔符制作实现方法

    一.先看genesis原始孔符 孔符的作用:用于表示孔径的大小的一种代号, 当孔径检测时,可以按分孔图中的孔符对应的孔径尺寸对孔径检测. 在实际PCB行业通常不使用原始(图形)孔符,而使用字母孔符(如 ...

  5. hibernate基础简单入门1---helloword

    1:目录结果 2:实体类(student.java) package com.www.entity; public class Student { private int id; private St ...

  6. notepad + +使用步骤

    原文地址:https://blog.csdn.net/so_geili/article/details/79317001#一-安装notepad 一. 安装notepad + +   notepad+ ...

  7. 【学习笔记】OI玄学道—代码坑点

    [学习笔记]\(OI\) 玄学道-代码坑点 [目录] [逻辑运算符的短路运算] [\(cmath\)里的贝塞尔函数] 一:[逻辑运算符的短路运算] [运算规则] && 和 || 属于逻 ...

  8. mahjong

    题目描述 “为什么, 你们的力量在哪里得到如此地......”“我们比 1 分钟前的我们还要进步, 虽然很微小, 但每转一圈就会前进一寸.这就是钻头啊!”“那才是通向毁灭的道路.为什么就没有意识到螺旋 ...

  9. Win7 + VS2015 + CMake3.6.1-GUI + Makefile 编译开源库

    CMake生成Unicode版本VC工程 Just add this line in your top CMakeLists.txt file:     add_definitions(-DUNICO ...

  10. [转]linux之top命令

    转自:http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html 简介 top命令是Linux下常用的性能分析工具,能够实时显示系 ...