Advertisement
HjHimansh

Configuration System

Oct 9th, 2020
884
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int n, s0, k, b, m, a;
  6.     cin >> n >> s0 >> k >> b >> m >> a;
  7.  
  8.     vector<int> s(n, 0);
  9.     s[0] = s0;
  10.     for(int i=1; i<n; i++){
  11.         s[i] = ( (k * s[i-1] + b) % m ) + 1 + s[i-1];
  12.         //cout << s[i] << " ";
  13.     }
  14.     //cout << endl << endl;
  15.    
  16.     //obviously s will be in sorted order....
  17.     int i=0, j=n-1;
  18.     int answer = 0;
  19.    
  20.     while(i<=j){
  21.         int pro = s[i] * s[j];
  22.         if(pro <= a){
  23.             //it means that all the pairs with i = i and j <=j will be counted
  24.             answer += 2 * (j-i);    answer+= 1;
  25.             i++;
  26.         }
  27.         else{
  28.             j--;
  29.         }
  30.     }
  31.     cout << answer << endl;
  32.     return 0;
  33. }
  34.  
  35. /*
  36.     Area not more than a (of ceiling)
  37.    
  38.     First task is to generate s...
  39.         s[i] = [(k * s[i-1] + b) mod m] + 1 + s[i-1]   for 1 <= i < n
  40.  
  41.                 i  j
  42.             [2, 4, 6] a = 15
  43.             we've to find number of pairs whose product is <= 15
  44.            
  45.    
  46.  
  47. */
Advertisement
RAW Paste Data Copied
Advertisement