Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("h1.in");
  8. ofstream fout("h1.out");
  9.  
  10.  
  11. unordered_set<int> myset;
  12.  
  13. int a[2000000],b[2000000],nr;
  14. int A,B,C,D,n,x,m,y;
  15.  
  16. int main()
  17. {
  18. fin>>A>>B>>C>>D>>n>>x>>m>>y;
  19. a[1]=x;
  20. for(int i=2;i<=n;i++)
  21. {
  22. a[i]=A+(a[i-1]*C+D)%(B-A+1);
  23. myset.insert(a[i]);
  24. }
  25. b[1]=y;
  26. for(int i=2;i<=m;i++)
  27. {
  28. b[i]=A+(b[i-1]*C+D)%(B-A+1);
  29. if(myset.find(b[i])!=myset.end())
  30. {
  31. nr++;
  32. myset.erase(b[i]);
  33. }
  34. }
  35. fout<<nr;
  36.  
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement