fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(NULL);
  8.  
  9. ll N, R;
  10. cin >> N >> R;
  11. ll ans = 0;
  12.  
  13. // Enumerate divisor pairs (x, y) of R with x < y
  14. for (ll x = 1; x * x <= R; ++x) {
  15. if (R % x == 0) {
  16. ll y = R / x;
  17. if (x < y && __gcd(x, y) == 1) {
  18. // For each valid (x, y), g can be 1..floor(N / y)
  19. ans += N / y;
  20. }
  21. }
  22. }
  23.  
  24. cout << ans;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5308KB
stdin
100 10
stdout
30