标签:blog io os ar for sp 数据 2014 log
题目:给你一组数,求出其中两两最大公约数中最大的值。
分析:数论。数据较小,直接枚举即可。
说明:注意输入格式。
#include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int data[101]; int gcd(int a, int b) { return a%b?gcd(b, a%b):b; } int main() { int n,m; scanf("%d",&n); while (getchar() != '\n'); while (n --) { char buf; int count = 0; while ((buf = getchar()) != '\n') if (buf >= '0' && buf <= '9') { ungetc(buf,stdin); scanf("%d",&data[count ++]); } int max = 1,temp; for (int i = 0 ; i < count ; ++ i) for (int j = 0 ; j < i ; ++ j) { temp = gcd(data[i], data[j]); if (max < temp) max = temp; } printf("%d\n",max); } return 0; }
标签:blog io os ar for sp 数据 2014 log
原文地址:http://blog.csdn.net/mobius_strip/article/details/40397959