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
- 235-Lowest Common Ancestor of a Binary Search Tree
- HDU 6298 Maximum Multiple(找規律)
- (杭電1019 最小公倍數) Least Common MultipleAST
- Logstash Multiple Pipelines
- JavaScript select multipleJavaScript
- hdu 2111 Saving HDU (DP)
- LLM multiple modal applicationsAPP
- 2.3.6.2 Synchronization of Multiple ApplicationsAPP
- Small Multiple(最短路)
- kubernetes traefik multiple namespacesnamespace
- 2.3.2 Application Common ObjectsAPPObject
- 2.2.3.1 Common Roles in a CDB
- 2.2.2.1 Common Users in a CDB
- C# Common utilsC#
- IRRATIONAL APPEAL TO COMMON BELIEFAPP
- POJ1426-Find The Multiple
- Multiple Books多賬薄
- 2024牛客多校第一場A Bit Common & A Bit More Common
- [LeetCode] 2028. Find Missing ObservationsLeetCode
- Shape of HDU
- HDU 3349
- HDU 2052(C語言+註釋)+HDU 2090C語言
- [Javascript] Common axios service for reuseabilityJavaScriptiOS
- ch13_common_class
- B-A Bit More Common
- Html language common symbolic entitiesHTMLSymbol
- 2.3.2.1 Creation of Application Common ObjectsAPPObject
- 2.2.6 Overview of Common Audit ConfigurationsView
- 2.2.4.3.1 What Makes a Grant Common
- Azure Terraform(六)Common ModuleORM
- Leetcode 14 Longest Common PrefixLeetCode
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- HDU 1240 Asteroids!AST
- hdu2083
- hdu5532
- HDU4787
- hdu5540