fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. using namespace chrono;
  5. using ull = unsigned long long;
  6. auto start = high_resolution_clock::now();
  7. void Code_By_Mohamed_Khaled() {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(nullptr);
  10. cout.tie(nullptr);
  11. #ifndef ONLINE_JUDGE
  12. freopen("input.txt", "r", stdin);
  13. freopen("output.txt", "w", stdout);
  14. #endif
  15. }
  16. void Time() {
  17. #ifndef ONLINE_JUDGE
  18. cout<<"\n";
  19. auto end = high_resolution_clock::now();
  20. auto duration = duration_cast<microseconds>(end - start);
  21. cout << "Time taken: " << duration.count() << " microseconds" << endl;
  22. #endif
  23. }
  24. int mod=998244353;
  25. ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
  26. ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
  27. ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
  28. int fast_power(int base,int power) {
  29. int res=1;
  30. while (power>0) {
  31. if (power%2) res=mul(res,base);
  32. base=mul(base,base);
  33. power/=2;
  34. }
  35. return res;
  36. }
  37. int main() {
  38. Code_By_Mohamed_Khaled();
  39. ll t;cin>>t;
  40. while (t--) {
  41. ll n,k;cin>>n>>k;ll ans=0;
  42. for (ll i=1;i*i<=k;i++) {
  43. if (k%i==0) {
  44. ll j=k/i;
  45. if (__gcd(i,j)==1) {
  46. if (i!=j)ans+=2*(n/(max(i,j)));
  47. else ans+=n/max(i,j);
  48. }
  49. }
  50. }
  51. cout<<ans<<"\n";
  52. }
  53. Time();
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5324KB
stdin
3
3 1
3 2
10 3
stdout
3
2
6