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]);
}
}
相關文章
- HDU 2028 Lowest Common Multiple Plus
- Lowest Common Ancestor
- LeetCode-Lowest Common Ancestor of a Binary TreLeetCode
- (杭電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
- Multiple Regression
- 密碼 hd 2043密碼
- 又見GCD hd 2504GC
- JavaScript select multipleJavaScript
- Small Multiple(最短路)
- DataGridView with multiple tableView
- Multiple Buffer Pools (83)
- Multiple Block Sizes (53)BloC
- HD Tune軟體怎麼用?使用HD tune檢測硬碟的方法教程硬碟
- 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
- 字串統計 hd 2017字串
- win10如何使用hd tune pro工具_win10使用hd tune pro工具的教程Win10
- 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