HDU 2028 Lowest Common Multiple Plus
/*
中文題意:
中文翻譯:
題目大意:求幾個數的最小公倍數
解題思路:將輸入的數存入陣列中,先求出前兩個數的最小公倍數,再用這個公倍數和其他的數求最小公倍數,直到數求完為止。
難點詳解:熟練掌握c++的簡單排序函式的格式和使用,兩數相乘再除以最大公約數就是這兩個數的最小公倍數。
關鍵點:gcd函式的運用,c++的簡單排序
解題人:lingnichong
解題時間:2014/07/30 10:30
*/
Lowest Common Multiple Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32773 Accepted Submission(s): 13357
Problem Description
求n個數的最小公倍數。
Input
輸入包含多個測試例項,每個測試例項的開始是一個正整數n,然後是n個正整數。
Output
為每組測試資料輸出它們的最小公倍數,每個測試例項的輸出佔一行。你可以假設最後的輸出是一個32位的整數。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[1010];
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
int n,i,t,min;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
min=a[0];
for(i=1;i<n;i++)
{
t=gcd(min,a[i]);
min=min/t*a[i];
}
printf("%d\n",min);
}
return 0;
}
相關文章
- Lowest Common Multiple Plus hd 2028
- Lowest Common Ancestor
- LeetCode-Lowest Common Ancestor of a Binary TreLeetCode
- HDU 6298 Maximum Multiple(找規律)
- (杭電1019 最小公倍數) Least Common MultipleAST
- [CareerCup] 4.7 Lowest Common Ancestor of a Binary Search Tree 二叉樹的最小共同父節點二叉樹
- 【LeetCode 235_二叉搜尋樹】Lowest Common Ancestor of a Binary Search TreeLeetCode
- HDU 1330 Nearest Common Ancestors(求兩個點的最近公共祖先)REST
- Multiple Regression
- JavaScript select multipleJavaScript
- Small Multiple(最短路)
- DataGridView with multiple tableView
- Multiple Buffer Pools (83)
- Multiple Block Sizes (53)BloC
- common.cssCSS
- 2.3.6.2 Synchronization of Multiple ApplicationsAPP
- Multiple Books多賬薄
- Multiple Render Targets in OpenGL with Cg
- MySql multiple servers on linuxMySqlServerLinux
- ssis multiple table to one file
- maven Multiple sourceDirectory外掛Maven
- Using Multiple Tablespaces (46)
- LLM multiple modal applicationsAPP
- android-Maintaining Multiple APKs,Creating Multiple APKs for Different API LevelsAndroidAIAPKAPI
- C# Common utilsC#
- Common Probability Distributions
- Common LISP Hints 中文Lisp
- Logstash Multiple Pipelines
- kubernetes traefik multiple namespacesnamespace
- Using Multiple Variables with the Same Name
- How to modify multiple items in the SAP menu
- 2.3.2 Application Common ObjectsAPPObject
- IRRATIONAL APPEAL TO COMMON BELIEFAPP
- Common threads: Awk by examplethread
- Html language common symbolic entitiesHTMLSymbol
- B-A Bit More Common
- ch13_common_class
- win10版本multiple editions是什麼版本_win10版本multiple editions啥意思Win10