Saleh127

uva 11827cpp

Jun 6th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int gcd( int a, int b )
  4. {
  5. while(b)
  6. {
  7. a=a%b;
  8. swap(a,b);
  9. }
  10. return a;
  11. }
  12.  
  13. int main()
  14. {
  15. int t;
  16. cin>>t;
  17. getchar();
  18. string x;
  19. while(t--)
  20. {
  21. getline(cin,x);
  22. stringstream ss(x);
  23. int a[10000],c,d=0,e,i,f,j,k,l;
  24. while(ss>>a[d])
  25. {
  26. ++d;
  27. f=0;
  28. for(i=0;i<d;i++)
  29. {
  30. for(j=i+1;j<d;j++)
  31. {
  32. k=gcd(a[i],a[j]);
  33. f=max(f,k);
  34. }
  35. }
  36. }
  37. cout<<f<<endl;
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment