Facebook
From Nguyễn Tiến Anh, 1 Month ago, written in C++.
This paste is a reply to beaunum from Nguyễn Tiến Anh - view diff
Embed
Download Paste or View Raw
Hits: 207
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. #define FOR(i,l,r) for (int i=l;i<=r;i++)
  4. #define FOD(i,r,l) for (int i=r;i>=l;i--)
  5. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  6.  
  7. using namespace std;
  8. int BCNN(int a, int b)
  9. {
  10.     int result = __gcd(a, b);
  11.     return a * b / result;
  12. }
  13. int main()
  14. {
  15.     freopen("countnum.inp","r",stdin);
  16.     freopen("countnum.out","w",stdout);
  17.     fast;
  18.     ll L,R,a,b; cin>>L>>R>>a>>b;
  19.     int t = BCNN(a,b);
  20.     ll s, sa , sb, sab;
  21.     s = R - L + 1;
  22.     sa = s/a;
  23.     sb = s/b;
  24.     sab = (R / t) - ((L-1) / t);
  25.     cout<< s - (sa + sb - sab);
  26. }
  27.  
  28.