/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 764.0 KiB
#3 Accepted 299ms 560.0 KiB
#4 Accepted 300ms 564.0 KiB
#5 Accepted 300ms 564.0 KiB
#6 Accepted 95ms 764.0 KiB
#7 Accepted 299ms 564.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll harmonious_pairs(ll N) {
    ll m = (ll)std::sqrt((long double)N);
    ll partial = 0;
    for (ll k = 1; k <= m; ++k) partial += N / k;
    ll H = (partial << 1) - m * m;   // 2*partial - m^2
    return H - N;                    // subtract N per formula
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while (T--) {
        ll N; cin >> N;
        cout << harmonious_pairs(N) << '\n';
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1207 D2. GCD equal Absolute Value (Hard Version)
Language
C++11 (G++ 13.2.0)
Submit At
2025-07-31 06:37:45
Judged At
2025-07-31 06:37:45
Judged By
Score
100
Total Time
300ms
Peak Memory
764.0 KiB