Advertisement
Guest User

Untitled

a guest
May 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define mx 1000000
  4.  
  5. long long gcd();
  6. long long convert();
  7.  
  8. int main()
  9. {
  10. int T;
  11. scanf("%d", &T);
  12.  
  13. char s[mx], store[22];
  14.  
  15. while (T--)
  16. {
  17. scanf(" %[^\n]", s);
  18.  
  19. long long ara[100];
  20.  
  21. long long i, j, k = 0, x = 0, n, GCD, max_gcd = 1;
  22.  
  23. for (i = 0; i <= strlen(s); i++)
  24. {
  25. if (s[i] == ' ' || s[i] == '\0')
  26. {
  27. if (s[i+1] == ' ')
  28. continue;
  29.  
  30. store[k] = '\0';
  31.  
  32. n = convert(store);
  33. ara[x++] = n;
  34. k = 0;
  35. }
  36.  
  37. else
  38. {
  39. store[k++] = s[i];
  40. }
  41. }
  42.  
  43. for (i = 0; i < x-1; i++)
  44. {
  45. for (j = i+1; j < x; j++)
  46. {
  47. GCD = gcd(ara[i], ara[j]);
  48.  
  49. if (max_gcd < GCD)
  50. max_gcd = GCD;
  51. }
  52. }
  53.  
  54. printf("%lld\n", max_gcd);
  55.  
  56. }
  57.  
  58. return 0;
  59. }
  60.  
  61. long long convert(char store[])
  62. {
  63. long long num = 0, i;
  64.  
  65. for (i = 0; i < strlen(store); i++)
  66. {
  67. num = num*10 + store[i] - '0';
  68. }
  69. return num;
  70. }
  71.  
  72. long long gcd(long long a, long long b)
  73. {
  74. if (a < b)
  75. return gcd(b, a);
  76.  
  77. if (a == b || b == 0)
  78. return a;
  79.  
  80. else
  81. return gcd(b, a%b);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement