poj3370(鸽巢原理-与2356一样)
来源:互联网 发布:js调用身份证读取器 编辑:程序博客网 时间:2024/05/20 18:18
http://poj.org/problem?id=3370
Description
Every year there is the same problem at Halloween: Eachneighbour is only willing to give a certain total number of sweetson that day, no matter how many children call on him, so it mayhappen that a child will get nothing if it is too late. To avoidconflicts, the children have decided they will put all sweetstogether and then divide them evenly among themselves. From lastyear's experience of Halloween they know how many sweets they getfrom each neighbour. Since they care more about justice than aboutthe number of sweets they get, they want to select a subset of theneighbours to visit, so that in sharing every child receives thesame number of sweets. They will not be satisfied if they have anysweets 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 integersc and n (1 ≤ c ≤n ≤ 100000), the number of children and the number ofneighbours, respectively. The next line containsn space separated integersa1 , ... ,an (1 ≤ ai ≤100000 ), where airepresents the number of sweets the children get if they visitneighbour i.
The last test case is followed by two zeros.
Output
For each test case output one line with the indices of theneighbours the children should select (here, indexi corresponds to neighbouri who gives a total number ofai sweets). If there is nosolution where each child gets at least one sweet print "no sweets"instead. Note that if there are several solutions where each childgets at least one sweet, you may print any of them.
Sample Input
4 5
1 2 3 7 5
3 6
7 11 2 5 13 17
0 0
Sample Output
3 5
2 3 4
Source
#include
#include
using namespace std;
#define maxn 100010
int a[maxn];
int b[maxn];
int main()
{