Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- unsigned int cur = 0;
- unsigned int nextRand(int a, int b)
- {
- cur = cur * a + b;
- return cur >> 8;
- }
- int inverse(vector<int> &mas)
- {
- int sum = 0;
- for (int i = mas.size()-1; i > 0; --i)
- {
- for (int j = 0; j < i; ++j)
- {
- if (mas[j] > mas[i])
- sum++;
- }
- }
- return sum;
- }
- int main() {
- //ifstream in("invcnt.in");
- //ofstream out("invcnt.out");
- int n, m, a, b;
- cin >> n >> m >> a >> b;
- vector <int> mas(n);
- for (int i = 0; i < n; i++)
- mas[i] = (int)nextRand(a, b) % m;
- cout << inverse(mas);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement