http://acm.hdu.edu.cn/showproblem.php?pid=2028

深夜十二点水的题,第一次wa,不过后来看看很简单,gcd求最大公约数,然后每次求出最小公倍数。。。最后知道用该数除以最大公约数再乘以本身就可以了

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int gcd(int a,int b)

{

    return b==0?a:gcd(b,a%b);

}

int main()

{

    int n,a,b,k;

    while(scanf("%d",&n)!=EOF)

    {

          scanf("%d",&b);

          for(int i=1;i<n;++i)

          {

                  scanf("%d",&a);

                  k=gcd(b,a);

                  b=b/k*a;

          }

          printf("%d\n",b);

    }

    //system("pause");

    return 0;

}

相关文章:

  • 2021-12-12
  • 2022-12-23
  • 2022-01-03
  • 2021-11-30
  • 2021-10-01
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-23
  • 2022-03-03
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案