Advertisement
NAbdulla

Maximum GCD

Aug 7th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. /****************************************************************************************
  2.    *  Md. Abdulla Al Mamun (Nayon)
  3.    *  ID: 1306001
  4.    *  Session: 2013-2014
  5.    *  Department of Computer Science and Engineering
  6.    *  Begum Rokeya University, Rangpur (BRUR)
  7.    *
  8.    *  Project Name:         Maximum GCD
  9.    *  File Created on:      Friday, 2015-08-07-21.22.01
  10.    *  Current File:         E:\My Codes\C and C++\Projects\Maximum GCD\main.cpp
  11.    *  Language:             English (U.S.)
  12.    *  Encoding:             windows-1252
  13. *****************************************************************************************/
  14. #include <iostream>
  15. #include <cstdio>
  16. #include <string>
  17. #include <cstring>
  18. #include <algorithm>
  19. #include <vector>
  20. #include <cmath>
  21. #include <queue>
  22.  
  23. using namespace std;
  24.  
  25. int gcd(int a, int b)
  26. {
  27.     int t;
  28.     while(b != 0){
  29.         t = a%b;
  30.         a = b;
  31.         b = t;
  32.     }
  33.     return a;
  34. }
  35.  
  36. int main()
  37. {
  38.     int N, M, i, j, maxi, nums[105];
  39.     char c;
  40.     scanf("%d", &N);
  41.     while(N--){
  42.         i = 0;
  43.         while(scanf("%d", &M)){
  44.             nums[i++] = M;
  45.             c = getchar();
  46.             if(c == '\n')break;
  47.         }
  48.         M = i;
  49.         maxi = 0;
  50.         int g;
  51.         for(i = 0; i < M-1; i++){
  52.             for(j = 0; j < M; j++){
  53.                 if(j != i){
  54.                     g = gcd(nums[i], nums[j]);
  55.                     if(maxi < g)maxi = g;
  56.                 }
  57.             }
  58.         }
  59.         printf("%d\n", maxi);
  60.     }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement