Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_set>
- #include <fstream>
- using namespace std;
- ifstream fin("h1.in");
- ofstream fout("h1.out");
- unordered_set<int> myset;
- int a[2000000],b[2000000],nr;
- int A,B,C,D,n,x,m,y;
- int main()
- {
- fin>>A>>B>>C>>D>>n>>x>>m>>y;
- a[1]=x;
- for(int i=2;i<=n;i++)
- {
- a[i]=A+(a[i-1]*C+D)%(B-A+1);
- myset.insert(a[i]);
- }
- b[1]=y;
- for(int i=2;i<=m;i++)
- {
- b[i]=A+(b[i-1]*C+D)%(B-A+1);
- if(myset.find(b[i])!=myset.end())
- {
- nr++;
- myset.erase(b[i]);
- }
- }
- fout<<nr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement