/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 30ms 532.0 KiB
#2 Time Exceeded ≥1100ms ≥532.0 KiB
#3 Time Exceeded ≥1098ms ≥532.0 KiB

Code

#include <bits/stdc++.h>
#define nl '\n'
#define ll long long
#define all(c) c.begin(),c.end()
#define print(c) for(auto e : c) cout << e << " "; cout << nl
using namespace std;
int gcd(int a, int b) { while (b != 0) { int temp = b; b = a % b; a = temp; } return a; }
void solve()
{
    int n; cin >> n;

    // ll cnt = n-1;
    // for (int i = 2; i <= n; i++)
    // {
    //     if((i + i) <= n && gcd(i, 2 * i) == i) cnt++;
    // }
    
    // cout << cnt << nl;

    ll cnt = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if(gcd(i, j) == abs(i - j)) cnt++;
        }
    }
    
    cout << cnt << nl;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int t; cin >> t;
    for(int tt = 1; tt <= t; tt++)
    {
        // cout << "TEST CASE-" << tt << nl;
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1206 D1. GCD equal Absolute Value (Easy Version)
Contest
Educational Round 1
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 17:59:38
Judged At
2025-07-14 17:59:38
Judged By
Score
0
Total Time
≥1100ms
Peak Memory
≥532.0 KiB