B - Aesthetics in poetry
题意:
N个数 找一个n的因数k然后 这n个数取余k得到n-1种结果。
另一个要求是这n种取余结果出现的次数得=n/k。
. 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.
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;
# define maxn 25000
# define inf 0x3f3f3f3f
long long n,a[maxn],m;
map<long long,int>mmp;
int main()
{
bool flag=0;
cin>>n;
for(int i=0; i<n; i++)
cin>>a[i];
for(int i=2; i<=n; i++)
{
if(n%i==0)
{
mmp.clear();
for(int j=0; j<n; j++)
{
mmp[a[j]%i]++;
}
if(mmp.size()==i)
{
bool f=0;
for(int j=0; j<i; j++)
{
if(mmp[j]!=n/i)
{
f=1;
break;
}
}
if(f==0)
{
flag=1;
cout<<i<<endl;
break;
}
}
}
}
if(flag==0)
cout<<-1<<endl;
return 0;
}