結果
| 問題 | 
                            No.1593 Perfect Distance
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-07-09 21:21:33 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4 ms / 2,000 ms | 
| コード長 | 735 bytes | 
| コンパイル時間 | 954 ms | 
| コンパイル使用メモリ | 98,276 KB | 
| 最終ジャッジ日時 | 2025-01-22 20:24:14 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
ull Isqrt(ull const &x){
    ull ret = (ull)sqrtl(x);
    while(ret > 0 && ret*ret > x) --ret;
    while(x - ret*ret > 2*ret) ++ret;
    return ret;
}
int main() {
    ll n;
    cin >> n;
    int ans = 0;
    for (ll i = 1; i <= n; ++i) {
        ll p = Isqrt(n*n-i*i);
        if(p > 0 && p*p+i*i == n*n) ans++;
    }
    cout << ans << "\n";
    return 0;
}