Pagini recente » Cod sursa (job #107771) | Cod sursa (job #3255296) | Cod sursa (job #1427634) | Cod sursa (job #666331) | Cod sursa (job #2732094)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("muzica.in");
ofstream g("muzica.out");
const int hashnr=49157;
vector <vector<unsigned>> music_map(hashnr);
int main()
{
int N,M,i,j,nr=0,song;
unsigned long long A,B,C,D,E,aux;
f>>N>>M;
f>>A>>B>>C>>D>>E;
for (i=0; i<N; i++)
{
f>>song;
music_map[song%hashnr].push_back(song);
}
for (i=0; i<music_map[A%hashnr].size(); ++i)
if (music_map[A%hashnr][i]==A)
{
nr++;
swap(music_map[A%hashnr][i],music_map[A%hashnr][music_map[A%hashnr].size()-1]);
music_map[A%hashnr].pop_back();
break;
}
for (i=0; i<music_map[B%hashnr].size(); ++i)
if (music_map[B%hashnr][i]==B)
{
nr++;
swap(music_map[B%hashnr][i],music_map[B%hashnr][music_map[B%hashnr].size()-1]);
music_map[B%hashnr].pop_back();
break;
}
for (i=0; i<M-2; ++i)
{
aux=(1LL*C*B+1LL*D*A)%E;
A=B;
B=aux;
for (j=0; j<music_map[B%hashnr].size(); ++j)
if (music_map[B%hashnr][j]==B)
{
nr++;
swap(music_map[B%hashnr][j],music_map[B%hashnr][music_map[B%hashnr].size()-1]);
music_map[B%hashnr].pop_back();
break;
}
}
g<<nr;
}