A. DZY Loves Hash

来源:互联网 发布:淘宝上买iphone店铺 编辑:程序博客网 时间:2024/04/30 07:01
A. DZY Loves Hash
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

DZY has a hash table with p buckets, numbered from0 top - 1. He wants to insertn numbers, in the order they are given, into the hash table. For thei-th numberxi, DZY will put it into the bucket numberedh(xi), whereh(x) is the hash function. In this problem we will assume, thath(x) = x mod p. Operationa mod b denotes taking a remainder after divisiona by b.

However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after thei-th insertion, you should output i. If no conflict happens, just output-1.

Input

The first line contains two integers, p andn(2 ≤ p, n ≤ 300). Thenn lines follow. Thei-th of them contains an integer xi(0 ≤ xi ≤ 109).

Output

Output a single integer — the answer to the problem.

Sample test(s)
Input
10 5021534153
Output
4
Input
5 501234
Output
-1

//水题不多说

//AC代码

#include<iostream>#include<queue>#include<algorithm>#include<cstdio>#include<cstring>#include<string>#include<map>using namespace std;int main(){    int p,n,x,y,j;    int z[301];    //while(1)    //{        cin>>p>>n;        map<int,int>Map;        memset(z,0,sizeof(z));        j=0;        for(int i=1;i<=n;i++)        {            cin>>x;            y=x%p;            Map[y]+=1;            if(Map[y]>1)            {                z[j++]=i;            }        }        if(j!=0)        {            cout<<z[0]<<endl;        }        else            cout<<-1<<endl;    //}    return 0;}



 

0 0