Advertisement
Guest User

Untitled

a guest
May 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. //#include<cstdlib>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int n, a, b, tab[1000];
  10.  
  11. int NWD(int a, int b){
  12.     while((a!=0) || (b!=0)){
  13.         if(a>b)
  14.             a=a%b;
  15.         else
  16.             b=b%a;
  17.     }
  18. return max(a,b);
  19. }
  20.  
  21. int NWW(int a,int b){
  22.      a*=b/NWD(a,b);
  23. return a;
  24. }
  25.  
  26. int main()
  27. {
  28. cin >> n;
  29.  
  30.     for (int i=0; i<n; i++){
  31.     cin >> a;
  32.             for(int j=0; j<a; j++)
  33.             cin >> tab[j];
  34.                
  35.     b=NWW(tab[0],tab[1]);
  36.     cout << b << endl;
  37.     cout << tab[0] << endl;
  38.     cout << tab[1] << endl;
  39.         for (int j=2; j<a; j++)
  40.             b=NWW(b,tab[j]);
  41.            
  42.    
  43.     cout << b << endl;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement