Description
Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a child will get nothing if it is too late. To avoid conflicts, the children have decided they will put all sweets together and then divide them evenly among themselves. From last year's experience of Halloween they know how many sweets they get from each neighbour. Since they care more about justice than about the number of sweets they get, they want to select a subset of the neighbours to visit, so that in sharing every child receives the same number of sweets. They will not be satisfied if they have any sweets left which cannot be divided. Your job is to help the children and present a solution.
Input
The input contains several test cases.
The first line of each test case contains two integers c and n ( ≤ c ≤ n ≤ ), the number of children and the number of neighbours, respectively. The next line contains nspace separated integers a1 , ... , an ( ≤ ai ≤ ), where ai represents the number of sweets the children get if they visit neighbour i. The last test case is followed by two zeros.
Output
For each test case output one line with the indices of the neighbours the children should select (here, index i corresponds to neighbour i who gives a total number of ai sweets). If there is no solution where each child gets at least one sweet print "no sweets" instead. Note that if there are several solutions where each child gets at least one sweet, you may print any of them.
Sample Input
Sample Output
Source
和上一题 poj2356 差不多
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
using namespace std;
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 100006
#define inf 1e12
ll n,m;
ll sum[N];
ll vis[N];
ll a[N];
ll tmp[N];
int main()
{
while(scanf("%I64d%I64d",&n,&m)==){
if(n== && m==){
break;
}
memset(sum,,sizeof(sum));
for(ll i=;i<=m;i++){
//ll x;
scanf("%I64d",&a[i]);
sum[i]=sum[i-]+a[i];
} memset(vis,,sizeof(vis));
memset(tmp,,sizeof(tmp));
for(ll i=;i<=m;i++){
ll x=sum[i]%n;
if(vis[x]){
ll y=tmp[x];
//printf("%d\n",i-y);
for(ll j=y+;j<i;j++){
printf("%I64d ",j);
}
printf("%d\n",i);
break; }
if(x==){
//printf("%d\n",i);
for(ll j=;j<i;j++){
printf("%I64d ",j);
}
printf("%d\n",i);
break;
}
vis[x]=;
tmp[x]=i;
} }
return ;
}