hdu_1019_Least Common Multiple_201310290920
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
//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的更多相关文章
- Socket聊天程序——Common
写在前面: 上一篇记录了Socket聊天程序的客户端设计,为了记录的完整性,这里还是将Socket聊天的最后一个模块--Common模块记录一下.Common的设计如下: 功能说明: Common模块 ...
- angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)
common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...
- Common Bugs in C Programming
There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...
- ANSI Common Lisp Practice - My Answers - Chatper - 3
Ok, Go ahead. 1 (a) (b) (c) (d) 2 注:union 在 Common Lisp 中的作用就是求两个集合的并集.但是这有一个前提,即给的两个列表已经满足集合的属性了.具体 ...
- [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 ...
- [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 ...
- [LeetCode] Longest Common Prefix 最长共同前缀
Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...
- 48. 二叉树两结点的最低共同父结点(3种变种情况)[Get lowest common ancestor of binary tree]
[题目] 输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点. 二叉树的结点定义如下: C++ Code 123456 struct BinaryTreeNode { int ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
随机推荐
- 洛谷P1341 无序字母对(欧拉回路)
P1341 无序字母对 题目描述 给定n个各不相同的无序字母对(区分大小写,无序即字母对中的两个字母可以位置颠倒).请构造一个有n+1个字母的字符串使得每个字母对都在这个字符串中出现. 输入输出格式 ...
- 推荐给Web前端开发人员的一些书籍(从基础到架构阶段)
有很多人问我说作为一个前端开发人员都需要看一些什么书籍,尤其是刚入门的新手,今天我整理了一下推荐给大家,大佬绕过. HTML+CSS+JavaScript 网页设计 从入门到精通 作为一个前端新手,强 ...
- JavaScript--Array 数组对象
Array 数组对象 数组对象是一个对象的集合,里边的对象可以是不同类型的.数组的每一个成员对象都有一个“下标”,用来表示它在数组中的位置,是从零开始的 数组定义的方法: 1. 定义了一个空数组: v ...
- 51nod 1222 莫比乌斯反演
思路: yhx找的反演题 题解已经烂大街了 #pragma GCC optimize("O3") //By SiriusRen #include <bits/stdc++.h ...
- 【BZOJ3527】[ZJOI2014] 力(FFT)
题目: BZOJ3527 分析: FFT应用第一题-- 首先很明显能把\(F_j\)约掉,变成: \[E_j=\sum _{i<j} \frac{q_i}{(i-j)^2}-\sum_{i> ...
- fcc 响应式框架Bootstrap 练习3
class="container-fluid"控制宽度100% <div class="container-fluid"> <h3 class ...
- Leetcode0143--Reorder List 链表重排
[转载请注明]https://www.cnblogs.com/igoslly/p/9351564.html 具体的图示可查看 链接 代码一 /** * Definition for singly-li ...
- C#入门经典 Chapter5 变量的更多内容
5.1类型转换 1.类型转换 1.1隐式转换:所有情况下可进行,编译器执行转换. 1.2显示转换 强制转换:强迫数据从一种类型转换为另一种类型. (<destinationType>)&l ...
- 电源管理POWER_SUPPLY_PROP_CAPACITY_LEVEL
电量计节点中有capacity_level 节点,这个是反应当前电池电流高低水平的参数. 分为critical low full normal 一般是由fg的芯片来判断,通过IIC读取,具体判断可参考 ...
- 易语言 打开exe可执行文件、打开网页
打开文件--------按钮被单击事件 直接复制以下代码即可 .版本 2 .子程序 _按钮58_被单击 运行 (“exe文件路径”, 假, ) 打开网站--------按钮被单击事件 直接复制以下代码 ...