結果

問題 No.1593 Perfect Distance
ユーザー CJ314CJ314
提出日時 2021-07-09 21:44:45
言語 C++17
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,735 ms
実行使用メモリ 3,544 KB
最終ジャッジ日時 2023-02-01 22:48:31
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
3,388 KB
testcase_01 AC 2 ms
3,448 KB
testcase_02 AC 1 ms
3,532 KB
testcase_03 AC 1 ms
3,508 KB
testcase_04 AC 1 ms
3,480 KB
testcase_05 AC 1 ms
3,436 KB
testcase_06 AC 1 ms
3,436 KB
testcase_07 AC 1 ms
3,384 KB
testcase_08 AC 2 ms
3,452 KB
testcase_09 AC 2 ms
3,452 KB
testcase_10 AC 3 ms
3,484 KB
testcase_11 AC 5 ms
3,488 KB
testcase_12 AC 7 ms
3,492 KB
testcase_13 AC 7 ms
3,544 KB
testcase_14 AC 8 ms
3,388 KB
testcase_15 AC 11 ms
3,408 KB
testcase_16 AC 15 ms
3,384 KB
testcase_17 AC 1 ms
3,540 KB
testcase_18 AC 1 ms
3,388 KB
testcase_19 AC 1 ms
3,536 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