Aesthetics in poetry Gym - 101879B

版权声明:本文为博主瞎写的,请随便转载 https://blog.csdn.net/sdut_jk17_zhangming/article/details/82192028

One of the greatest poets in Portuguese language was Luiz Vaz de Camões, born in Lisbon circa 1524. Camões works are fundamental reading for high school students in countries such as Brazil or Portugal. Many consider his 5- and 7-syllable poems and his sonnets (with 14 verses) to be the most important lyrical work in Portuguese of all time.

Camões was a visionary in his own time. His work has been studied from many aspects: historical, cultural, symbolical, and so on. Carlitos "the efficient" Nunes is studying aesthetics in Camões' poetry. He is especially interested in a metric based on the size of the verses of a poem. We define this metric as follows. Suppose we have a poem made of NN verses. We say that the poem is KK-elegant if K>1K>1, NN is a multiple of KK and, moreover, there are exactly N/KN/K verses whose sizes, when divided by KK, have remainders equal to ii, for i=0,1,…,K−1i=0,1,…,K−1. Note that a single poem may be KK-elegant for several distinct values of KK.

Carlitos already processed the data from poems by Camões and now he needs your help to determine the smallest elegance in each of the poems.

Input

The input has two lines. The first line has an integer NN, the number of verses in the poem. In the second line you are given NN integers, say ℓ1,ℓ2,…,ℓNℓ1,ℓ2,…,ℓN, such that ℓiℓirepresents the size of the iith verse of the poem.

Constraints

  • 1≤N≤2⋅1031≤N≤2⋅103
  • 1≤ℓi≤1091≤ℓi≤109

Output

A single integer KK, the smallest integer such that the poem is KK-elegant. If no such integer exists, print "-1".

Examples

Input

6
3 6 1 7 8 14

Output

扫描二维码关注公众号,回复: 3035031 查看本文章
2

Input

5
17 21 14 35 13

Output

5

Note

In the first case, if K=2K=2, then 6,86,8 and 1414 (respectively, 33, 11 and 77) have remainder 00 (respectively, remainder 11) when divided by KK.

#include <bits/stdc++.h>
using namespace std;
int a[2005], num[2005];
int main()
{
    int n, m, i, j, k;
    scanf("%d", &n);
    for(i = 1; i <= n; i++)scanf("%d", &a[i]);
    for(i = 2; i <= n; i++)
    {
        if(n % i != 0)continue;
        memset(num, 0, sizeof(num));
        for(j = 1; j <= n; j++)
        {
            num[a[j] % i]++;
            if(num[a[j] % i] > n / i)break;
        }
        if(j == n + 1)
        {
            break;
        }
    }
    if(i == n + 1)printf("-1\n");
    else printf("%d\n", i);
    return 0;
}


猜你喜欢

转载自blog.csdn.net/sdut_jk17_zhangming/article/details/82192028