Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int n, s0, k, b, m, a;
- cin >> n >> s0 >> k >> b >> m >> a;
- vector<int> s(n, 0);
- s[0] = s0;
- for(int i=1; i<n; i++){
- s[i] = ( (k * s[i-1] + b) % m ) + 1 + s[i-1];
- //cout << s[i] << " ";
- }
- //cout << endl << endl;
- //obviously s will be in sorted order....
- int i=0, j=n-1;
- int answer = 0;
- while(i<=j){
- int pro = s[i] * s[j];
- if(pro <= a){
- //it means that all the pairs with i = i and j <=j will be counted
- answer += 2 * (j-i); answer+= 1;
- i++;
- }
- else{
- j--;
- }
- }
- cout << answer << endl;
- return 0;
- }
- /*
- Area not more than a (of ceiling)
- First task is to generate s...
- s[i] = [(k * s[i-1] + b) mod m] + 1 + s[i-1] for 1 <= i < n
- i j
- [2, 4, 6] a = 15
- we've to find number of pairs whose product is <= 15
- */
Advertisement
RAW Paste Data
Copied
Advertisement