1.题目链接。暴力可做,但是有一点技巧。利用了素数筛的思想,首先我们知道,k一定是n的因子,在这种情况下,如果我们找到了一个k,那么可以把他的倍数并且是n的因子同时筛掉。这是显然的。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
bool vis[maxn];
int a[maxn];
int n;
#pragma warning(disable:4996)
bool judge(int x)
{
map<int, int>mp1, mp2;
for (int i = 0; i < x; i++)++mp1[a[i]];
for (int i = x; i < n; i += x)
{
mp2.clear();
for (int j = i; j < i + x; j++)++mp2[a[j]];
if (mp1 != mp2)return false;
}
return 1;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
for (int i = 0; i < n; i++)scanf("%d", a + i);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n / 2; i++)
{
if(!vis[i]&&n%i==0)
if (judge(i))
{
vis[i] = 1;
for (int j = 2 * i; j <= n / 2; j += i)
if (n%j == 0)
vis[j] = 1;
}
}
vis[n] = 1;
bool ok = 0;
for (int i = 1; i <= n; i++)
{
if (vis[i] && ok)printf(" %d", i);
else if (vis[i]) { printf("%d", i); ok = 1; }
}
puts("");
}
}