#include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdint.h> #include <math.h> #include <stdlib.h> #include <iostream> #include <sstream> using namespace std; /* * Author: Andrew Stewart * Date: September 10, 2011 * Purpose: CSC 2700 Sec. 2 Homework * Problem: 11827 - Maximum GCD */ int gcd(int x, int y) { return y==0?x:gcd(y,x%y); } int main() { int n; string line; getline(cin,line); stringstream result(line); result >> n; for (int i=0; i<n; ++i) { getline(cin,line); int * num = new int[100]; stringstream result(line); int pos = 0; while(result >> num[pos++]) { } int M = 0; for (int j=0; j<100; j++) { for (int k=j+1; k<100; k++) { if (num[j]*num[k]==0)break; int x = gcd(num[j],num[k]); // cout << num[j] << " " << num[k] << " " << x << endl; M = x>M?x:M; } } cout << M << endl; } }The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Isaac Traxler