Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. using ll = long long;
  2.  
  3. // caculate number of points below (a/c)x+(b/c)
  4. // count of "STRICKTLY" below of the line
  5. // count of "STRICKTLY" upper of the X axis
  6. // find number in range [0, n)
  7. // a must not be negative
  8. // be carefull of overflow
  9.  
  10. ll calc(ll a,ll b,ll c,ll n){
  11.     if(!n)return 0;
  12.     ll tmp=a/c*n*(n-1)/2;
  13.     tmp+=b/c*n;
  14.     return tmp+calc(c,(a*n+b)%c,a%c,((a%c)*n+b%c)/c);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement