HDU 1019 Least Common Multiple
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                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\n", b); 32 } 33 34 35 fclose(stdin); 36 return 0; 37 }?
轉載于:https://www.cnblogs.com/livelihao/p/5294866.html
總結
以上是生活随笔為你收集整理的HDU 1019 Least Common Multiple的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Hello This Cruel Wor
 - 下一篇: MongoDB的快速手动安装