codeforces 299 A. Ksusha and Array

题目链接

题目就是让你找出一个数组中可以将这个数组中所有数整除的数,很明显,如果存在,这个数肯定是最小的一个。

//cf 299A
//2013-06-05-20.51
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
const int maxn = 100005;
int a[maxn];

int main()
{
    int n;
    while (scanf("%d", &n) != EOF)
    {
        int m = 0x3f3f3f3f;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &a[i]);
            m = min(a[i], m);
        }
        int f = 1;
        for (int i = 0; i < n; i++)
        {
            if (a[i]%m != 0)
            {
                f = 0;
                break;
            }
        }
        if (f)
            printf("%d\n", m);
        else
            puts("-1");
    }
    return 0;
}


posted @ 2013-06-05 20:59  xindoo  阅读(155)  评论(0编辑  收藏  举报