Aesthetics in poetry Gym - 101879B

Aesthetics in poetry

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

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 K.
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;

long long a[3010],b[3010];
int main()
{
    long long n,i,t,j;
    scanf("%lld",&n);
    for(i=0;i<n;i++)scanf("%lld",&a[i]);
    for(i=2;i<=n;i++)
    {
        if(n%i==0)///找n的最小因子
        {
            memset(b,0,sizeof(b));///初始化
            for(j=0;j<n;j++)
            {
                int k=a[j]%i;
                b[k]++;
            }
            t=i;
            for(j=0;j<i;j++)
            {
                if(b[j]!=n/i)t=0;
                if(t==0)break;
            }
            if(t!=0)break;
        }
    }
    if(t)
    cout<<t<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值