Cod sursa(job #1259511)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 10 noiembrie 2014 09:17:58
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.21 kb
#include <cstdio>
#include <vector>
#define MOD 666013

using namespace std;

int n,m,a,b,c,d,e,i,ind,x,SOL,X,Y,VAL;
vector <int> h[MOD+10];
vector <int>::iterator it;

vector <int>::iterator find(int x)
 {
     for (it=h[ind].begin();it!=h[ind].end();it++) if (*it==x) return it;
     return it;
 }

void insert(int x)
  {
      if (it==h[ind].end()) h[ind].push_back(x);
  }

int main()
{
    freopen("muzica.in","r",stdin);
    freopen("muzica.out","w",stdout);

    scanf("%d %d", &n, &m);
    scanf("%d %d %d %d %d", &a, &b, &c ,&d, &e);
    for (i=1;i<=n;++i)
    {
        scanf("%d", &x);
        ind=x%MOD;
        it=find(x);
        insert(x);
    }

    m-=2;
    ind=a%MOD;
    it=find(a);
    if (it!=h[ind].end())
    {
        SOL++;
        h[ind].erase(it);
    }

    ind=b%MOD;
    it=find(b);
    if (it!=h[ind].end())
    {
        SOL++;
        h[ind].erase(it);
    }


    X=a; Y=b;
    for (;m;--m)
    {
        VAL=(c*X+d*Y)%e;
        ind=VAL%MOD;
        it=find(VAL);
        if (it!=h[ind].end())
        {
            SOL++;
            h[ind].erase(it);
        }
        X=Y; Y=VAL;
    }

    printf("%d\n", SOL);

    return 0;
}