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 ;
}

poj 3370 Halloween treats(鸽巢原理)的更多相关文章

  1. POJ 3370 Halloween treats 鸽巢原理 解题

    Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include ...

  2. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448 ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 3370 Halloween treats( 鸽巢原理简单题 )

    链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户 ...

  5. [POJ 3370] Halloween treats

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7143   Accepted: 2641 ...

  6. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...

  7. 鸽巢原理应用-分糖果 POJ 3370 Halloween treats

    基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...

  8. [POJ3370]&[HDU1808]Halloween treats 题解(鸽巢原理)

    [POJ3370]&[HDU1808]Halloween treats Description -Every year there is the same problem at Hallowe ...

  9. POJ3370&amp;HDU1808 Halloween treats【鸽巢原理】

    题目链接: id=3370">http://poj.org/problem?id=3370 http://acm.hdu.edu.cn/showproblem.php?pid=1808 ...

随机推荐

  1. JAVA获得系统配置文件的System Properties

    来个java获得系统配置文件的 public class SystemProperties { public static void main(String[] args) { Properties ...

  2. copy模块

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #copy复制对象 #作用:提供一些函数,可以使用潜复制和深复制进行 ...

  3. Hibernate框架后续

    持久化对象的唯一标识OID 1:我们都知道,在java中按照内存地址来区分同一个类的不同对象        而关系数据库按照主键来区分一条记录 在Hibernate中使用OID来建立内存中的对象和数据 ...

  4. Jpeg(模拟)

    Jpeg Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  5. 《TCP/IP具体解释卷2:实现》笔记--4种不同类型的mbuf

    mbuf的主要用途是保存子进程和网络接口间互相传递的用户数据.但mbuf也用于保存其它各种数据:源于目的地址.插口 选项等等. 以下介绍我们要遇到的四种类型的mbuf,它们根据在成员m_flag中填写 ...

  6. mysql、添加和删除用户、添加权限

    创建用户      mysql>insert into mysql.user(Host,User,Password) values("localhost","tes ...

  7. (转) class II

    Overloading operators   Classes, essentially, define new types to be used in C++ code. And types in ...

  8. shell中的数学运算

    shell中要进行数学运算通常有3中方法: expr命令 比如 expr 1 + 6就会返回7,使用expr的缺点就是碰到乘法运算,或者加括号(因为它们在shell中有其他意义),需要使用转义,比如: ...

  9. mysql install

    ./scripts/mysql_install_db --user=mahao01 --basedir=/home/mahao01/local/mysql --datadir=/home/mahao0 ...

  10. jq插件处女座 图片轮播

    好久没写博客了,变得好懒呀,无地自容.最近一直在学sass和jq插件的写法,照猫画虎的谢了一个jq的插件,也算是第一次真正称得上插件的插件 ,废话不多说 上代码 (function($) { $.fn ...