結果

問題 No.1593 Perfect Distance
ユーザー CJ314CJ314
提出日時 2021-07-09 21:44:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 198,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 08:20:44
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 13 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long ceil_sqrt(const long long x) {
    assert(x >= 0);
    long long ok = 3'037'000'500, ng = -1;
    while (ng + 2 <= ok) {
        const long long mid = (ok + ng) / 2;
        if (mid * mid >= x) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N;
    cin >> N;

    ll ans = 0;
    for (ll i = 1; i * i < N * N; i++) {
        ll t = N * N - i * i;
        ll sqrt_t = ceil_sqrt(t);
        if (sqrt_t * sqrt_t == t) ans++;
    }
    cout << ans << "\n";
}
0