Least Common Multiple(hdu 1019)
2018-03-18 16:26
405 查看
题目:点击打开链接
求一组数的最小公倍数,其实方法是类似的,就是把前两个数的最大公倍数替换那两个数,依次进行……不过重点不是这个,而是#include<bits/stdc++.h>这个头文件里有__gcd(a,b),这样就不用自己写gcd()函数,在hdu测试了有用。。。
![](//img-blog.csdn.net/20180318162617648)
#include<bits/stdc++.h>
using namespace std;
long long a[1000];
int main()
{
int t,n;
while(scanf("%d",&t)==1)
{
while(t--)
{
scanf("%d",&n);
int ans=1;
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
for(int i=0;i<n-1;i++)
{
ans=__gcd(a[i],a[i+1]);//两个下划线
a[i+1]=a[i]/ans*a[i+1];
}
printf("%lld\n",a[n-1]);
}
}
return 0;
}
求一组数的最小公倍数,其实方法是类似的,就是把前两个数的最大公倍数替换那两个数,依次进行……不过重点不是这个,而是#include<bits/stdc++.h>这个头文件里有__gcd(a,b),这样就不用自己写gcd()函数,在hdu测试了有用。。。
#include<bits/stdc++.h>
using namespace std;
long long a[1000];
int main()
{
int t,n;
while(scanf("%d",&t)==1)
{
while(t--)
{
scanf("%d",&n);
int ans=1;
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
for(int i=0;i<n-1;i++)
{
ans=__gcd(a[i],a[i+1]);//两个下划线
a[i+1]=a[i]/ans*a[i+1];
}
printf("%lld\n",a[n-1]);
}
}
return 0;
}
相关文章推荐
- hdu_1019 Least Common Multiple(最小公倍数)
- HDU1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- hdu 1019Least Common Multiple(最大公约数)
- HDU 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- hdu 1019 Least Common Multiple(LCM的运用)
- hdu 1019 Least Common Multiple
- Least Common Multiple HDU - 1019
- HDU—— 1019 Least Common Multiple
- HDU 1019 Least Common Multiple 数学题
- hdu 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- HDU-1019-Least Common Multiple
- hdu1019 Least Common Multiple
- 杭电 HDU 1019 Least Common Multiple
- HDU 1019 Least Common Multiple
- hdu 1019 Least Common Multiple
- HDU 1019 Least Common Multiple