ADAFENCE - Ada and Fence
Ada the Ladybug owns a circular land. She wants to enclose it with fence. Anyway since nobody sells round planks, she has decided to fence it to shape of regular k-gon. Problem is, that there is only limited number or places (on circle) where pilars can be built. Ada has asked you, to find out the number of different regular k-gon shaped fences which can be built on her land (two k-gon's are considered different if they share NO common pillar).
Input
The first line will contain T, the number of test-cases.
Then T test-cases follow, each beginning with two integers 3 ≤ K ≤ N ≤ 105, 3 ≤ K ≤ 100, the number of places where pillar can be built and number of edges of regular k-gon
Afterward a line with N integers 1 ≤ Di ≤ 100 follow, meaning the length of arc between two consecutive points where pillar can be built. The sum of all lengths will be divisible by K.
Sum of N over all test-cases won't exceed 2*106
Output
For each test-case print the number of different regular k-gon shaped fences which can be built.
Example Input
3 5 3 1 2 3 2 1 15 4 1 2 2 2 1 2 2 1 1 2 1 2 1 2 2 10 5 1 1 1 1 1 1 1 1 1 1
Example Output
1 1 2
#include<bits/stdc++.h>
#define MAXN 100005
#define MAXM 10000005
using namespace std;
int d[MAXN],q[MAXM];
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
int n,k;
scanf("%d%d",&n,&k);
int sum=0;
memset(q,0,sizeof(q));
q[0]=1;
for(int i=0;i<n;i++)
{
scanf("%d",&d[i]);
sum+=d[i];
q[sum]=1;
}
int l=sum/k;
int ans=0;int cnt=0;
for(int i=0;i<l;i+=d[cnt++])
{
int flag=1;
for(int j=0;j<k;j++)
{
if(!q[j*l+i])
{
flag=0;
break;
}
}
if(flag)
ans++;
}
printf("%d\n",ans);
}
return 0;
}