結果

問題 No.1593 Perfect Distance
ユーザー parentheses
提出日時 2022-01-29 21:10:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 2,094 ms
コンパイル使用メモリ 191,584 KB
最終ジャッジ日時 2025-01-27 17:54:13
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
// --------------------------------------------------------


// 平方数判定: O(log n)
bool is_square_number(ll n) {
    ll l = 0, r = min(n, (ll)1e9);
    while (r - l > 1) {
        ll m = (l + r) / 2;
        (n <= m*m ? r : l) = m;
    }
    return r*r == n;
}


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

    ll N; cin >> N;

    ll ans = 0;
    FOR(x,1,N) {
        ll y2 = N*N - x*x;
        if (is_square_number(y2)) ans++;
    }
    cout << ans << endl;

    return 0;
}
// Verify: https://yukicoder.me/problems/no/1593
0