Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************************
- * Md. Abdulla Al Mamun (Nayon)
- * ID: 1306001
- * Session: 2013-2014
- * Department of Computer Science and Engineering
- * Begum Rokeya University, Rangpur (BRUR)
- *
- * Project Name: Maximum GCD
- * File Created on: Friday, 2015-08-07-21.22.01
- * Current File: E:\My Codes\C and C++\Projects\Maximum GCD\main.cpp
- * Language: English (U.S.)
- * Encoding: windows-1252
- *****************************************************************************************/
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- #include <queue>
- using namespace std;
- int gcd(int a, int b)
- {
- int t;
- while(b != 0){
- t = a%b;
- a = b;
- b = t;
- }
- return a;
- }
- int main()
- {
- int N, M, i, j, maxi, nums[105];
- char c;
- scanf("%d", &N);
- while(N--){
- i = 0;
- while(scanf("%d", &M)){
- nums[i++] = M;
- c = getchar();
- if(c == '\n')break;
- }
- M = i;
- maxi = 0;
- int g;
- for(i = 0; i < M-1; i++){
- for(j = 0; j < M; j++){
- if(j != i){
- g = gcd(nums[i], nums[j]);
- if(maxi < g)maxi = g;
- }
- }
- }
- printf("%d\n", maxi);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement