Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define mx 1000000
- long long gcd();
- long long convert();
- int main()
- {
- int T;
- scanf("%d", &T);
- char s[mx], store[22];
- while (T--)
- {
- scanf(" %[^\n]", s);
- long long ara[100];
- long long i, j, k = 0, x = 0, n, GCD, max_gcd = 1;
- for (i = 0; i <= strlen(s); i++)
- {
- if (s[i] == ' ' || s[i] == '\0')
- {
- if (s[i+1] == ' ')
- continue;
- store[k] = '\0';
- n = convert(store);
- ara[x++] = n;
- k = 0;
- }
- else
- {
- store[k++] = s[i];
- }
- }
- for (i = 0; i < x-1; i++)
- {
- for (j = i+1; j < x; j++)
- {
- GCD = gcd(ara[i], ara[j]);
- if (max_gcd < GCD)
- max_gcd = GCD;
- }
- }
- printf("%lld\n", max_gcd);
- }
- return 0;
- }
- long long convert(char store[])
- {
- long long num = 0, i;
- for (i = 0; i < strlen(store); i++)
- {
- num = num*10 + store[i] - '0';
- }
- return num;
- }
- long long gcd(long long a, long long b)
- {
- if (a < b)
- return gcd(b, a);
- if (a == b || b == 0)
- return a;
- else
- return gcd(b, a%b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement