zoukankan      html  css  js  c++  java
  • hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 34980    Accepted Submission(s): 14272


    Problem Description
    求n个数的最小公倍数。
     
    Input
    输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
     
    Output
    为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
     
    Sample Input
    2 4 6
    3 2 5 7
     
    Sample Output
    12
    70
     
    Author
    lcy
     
    Source
     
    PS:欧几里得算法gcd
     
     
     1 #include<iostream>
     2 #include<stdio.h>
     3 using namespace std;
     4 typedef __int64 inta;
     5 inta gcd(inta a,inta b)
     6 {
     7     if(b==0)
     8     return a;
     9     return gcd(b,a%b);
    10 }
    11 inta lcm(inta a,inta b)
    12 {
    13     return a*b/gcd(a,b);
    14 }
    15 int main()
    16 {
    17     int n;
    18     while(cin >> n)
    19     {
    20         __int64 a;
    21         __int64 vis=1;
    22         while(n--)
    23         {
    24             scanf("%I64d",&a);
    25             vis = lcm(vis,a);
    26         }
    27         printf("%I64d
    ",vis);
    28     }
    29     return 0;
    30 }
    View Code
  • 相关阅读:
    关于欧拉函数
    JavaWeb技术
    jQuery介绍
    Spring之事务管理
    Hibernate课堂笔记
    JSON简介
    Ajax简介
    Java代码生成图片验证码
    JAVA学习笔记——ClassLoader中getResource方法的路径参数
    JAVA OOP学习笔记——多态(polymorphism)
  • 原文地址:https://www.cnblogs.com/xuesen1995/p/4111900.html
Copyright © 2011-2022 走看看