結果

問題 No.800 四平方定理
ユーザー YamaKasaYamaKasa
提出日時 2020-11-18 23:42:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,925 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 164,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 15:17:41
合計ジャッジ時間 24,298 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 672 ms
4,380 KB
testcase_11 AC 742 ms
4,376 KB
testcase_12 AC 780 ms
4,376 KB
testcase_13 AC 599 ms
4,380 KB
testcase_14 AC 662 ms
4,380 KB
testcase_15 AC 789 ms
4,380 KB
testcase_16 AC 676 ms
4,376 KB
testcase_17 AC 675 ms
4,376 KB
testcase_18 AC 828 ms
4,376 KB
testcase_19 AC 829 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 837 ms
4,376 KB
testcase_23 AC 1,925 ms
4,376 KB
testcase_24 AC 1,589 ms
4,376 KB
testcase_25 AC 1,914 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1,576 ms
4,376 KB
testcase_29 AC 1,795 ms
4,376 KB
testcase_30 AC 1,583 ms
4,376 KB
testcase_31 AC 1,416 ms
4,376 KB
testcase_32 AC 1,652 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, D;
    cin >> N >> D;
    int cnt = 0;
    const int NN = N * N;
    int h, t, g, m;
    for (int x = 1; x <= N; x++) {
        g = x * x;
        for (int y = x ; y <= N; y++) {
            h = g + y * y - D;
            if (h > NN) break;
            if (h < 0) {
                m = max((int)sqrt(-h), y);
            } else {
                m = y;
            }
            for (int z = m; z <= N; z++) {
                t = h + z * z;
                if (t > NN) break;
                if (t <= 0) continue;
                int k = sqrt(t);
                if (k * k == t) {
                    if (x != y && y != z) cnt += 6;
                    else if (x == y && y != z) cnt += 3;
                    else if (x != y && y == z) cnt += 3;
                    else cnt += 1;
                } 
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}
0