zoukankan      html  css  js  c++  java
  • HDU 1019 Least Common Multiple

    多个数的最小公倍数

    数的类型不能为int ,而是选择long long 类型

    若是使用scanf, printf函数时 用%I64d,而不是%lld ,即使两种实质意义没什么不同,仅仅是平台不一样

    最小公倍数可以用辗转相除法,这里没有用,简单

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 int Common(int a, int b) {
     6     int t = (a < b )? a : b;
     7     while(t > 0) {
     8         if(a % t == 0 && b % t == 0)
     9             break;
    10         t --;
    11     }
    12     return t;
    13 }
    14 
    15 int main()
    16 {
    17 
    18     freopen("C:\Users\super\Documents\CB_codes\in.txt", "r", stdin);
    19     //freopen("C:\Users\super\Documents\CB_codes\out.txt","w",stdout);
    20     int T, n;
    21     long long int a, b;
    22     scanf("%d", &T);
    23     while(T --) {
    24         scanf("%d", &n);
    25         b = 1;
    26         for(int i = 0; i < n; i ++) {
    27             scanf("%I64d", &a);
    28             b = b * a / Common(a, b);
    29         }
    30 
    31         printf("%I64d
    ", b);
    32     }
    33 
    34 
    35     fclose(stdin);
    36     return 0;
    37 }
    ---------------- 人们生成的最美好的岁月其实就是最痛苦的时候,只是事后回忆起来的时候才那么幸福。
  • 相关阅读:
    [SCOI2003]严格N元树
    CF280 C. Game on Tree
    [HDU2281]Square Number
    [HDU5391]Zball in Tina Town
    [HDU3988]Harry Potter and the Hide Story
    [HDU5794]A Simple Chess
    [HDU5451]Best Solver
    [HDU1724]Ellipse
    [HDU6304]Chiaki Sequence Revisited
    [HDU6343]Graph Theory Homework
  • 原文地址:https://www.cnblogs.com/livelihao/p/5294866.html
Copyright © 2011-2022 走看看