Lowest Common Multiple Plus hd 2028
Problem Description
求n個數的最小公倍數。
Input
輸入包含多個測試例項,每個測試例項的開始是一個正整數n,然後是n個正整數。
Output
為每組測試資料輸出它們的最小公倍數,每個測試例項的輸出佔一行。你可以假設最後的輸出是一個32位的整數。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
求n個數的最小公倍數。
Input
輸入包含多個測試例項,每個測試例項的開始是一個正整數n,然後是n個正整數。
Output
為每組測試資料輸出它們的最小公倍數,每個測試例項的輸出佔一行。你可以假設最後的輸出是一個32位的整數。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
#include<stdio.h>
__int64 GCD(__int64 x,__int64 y)
{
if(x%y==0)
return y;
else
return GCD(y,x%y);
}
__int64 LCM(__int64 x,__int64 y)
{
return x*y/GCD(x,y);
}
int main()
{
__int64 a[100],n,i;
while(scanf("%I64d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%I64d",&a[i]);
for(i=0;i<n-1;i++)
{
a[i+1]=LCM(a[i],a[i+1]);
}
printf("%I64d\n",a[n-1]);
}
}
相關文章
- Lowest Common Ancestor
- 235-Lowest Common Ancestor of a Binary Search Tree
- (杭電1019 最小公倍數) Least Common MultipleAST
- JavaScript select multipleJavaScript
- Logstash Multiple Pipelines
- Small Multiple(最短路)
- 2.3.6.2 Synchronization of Multiple ApplicationsAPP
- LLM multiple modal applicationsAPP
- kubernetes traefik multiple namespacesnamespace
- IRRATIONAL APPEAL TO COMMON BELIEFAPP
- 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#
- Multiple Books多賬薄
- POJ1426-Find The Multiple
- 2024牛客多校第一場A Bit Common & A Bit More Common
- Picture hd 2052
- [LeetCode] 2028. Find Missing ObservationsLeetCode
- Leetcode 14 Longest Common PrefixLeetCode
- 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
- [Javascript] Common axios service for reuseabilityJavaScriptiOS
- ch13_common_class
- B-A Bit More Common
- Azure Terraform(六)Common ModuleORM
- 密碼 hd 2043密碼
- Big Number hd 1212
- the Sum of Cube hd 5053
- 不要62 hd 2089
- LeetCode之Find Common Characters(Kotlin)LeetCodeKotlin
- .NET Core Common Language Runtime (CoreCLR)
- PostgreSQL DBA(136) - Develop(Common Mistakes)SQLdev
- 2.2.5 Overview of Common and Local Objects in a CDBViewObject
- 2.2.2 Overview of Common and Local Users in a CDBView
- HDU 6298 Maximum Multiple(找規律)