fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. void Code_By_Mohamed_Khaled() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. cout.tie(nullptr);
  8. // #ifndef ONLINE_JUDGE
  9. // freopen("input.txt", "r", stdin);
  10. // freopen("output.txt", "w", stdout);
  11. // #endif
  12. }
  13. int main() {
  14. Code_By_Mohamed_Khaled();
  15. ll t;cin>>t;
  16. while (t--) {
  17. ll n,k;cin>>n>>k;ll ans=0;
  18. for (ll i=1;i*i<=k;i++) {
  19. if (k%i==0) {
  20. ll j=k/i;
  21. if (__gcd(i,j)==1) {
  22. if (i!=j)ans+=2*(n/(max(i,j)));
  23. else ans+=n/max(i,j);
  24. }
  25. }
  26. }
  27. cout<<ans<<"\n";
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0.85s 5288KB
stdin
20
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
10000000000000 10000000000000
stdout
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386
16386