結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-19 20:52:49 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,318 bytes |
| コンパイル時間 | 3,437 ms |
| コンパイル使用メモリ | 273,152 KB |
| 実行使用メモリ | 9,892 KB |
| 最終ジャッジ日時 | 2025-02-19 20:53:13 |
| 合計ジャッジ時間 | 22,905 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 TLE * 2 -- * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d; cin >> n >> d;
int ans = 0;
for(int x = 1; x <= n; x++) {
for(int y = x; y <= n; y++) {
int ans_xy = 0;
int a = abs(d - x*x - y*y); // z^2 - w^2
if(a == 0) {
ans_xy += n;
}
else if(a % 4 == 2) continue;
else if(a % 4 == 0) {
int b = a / 4;
for(int i = 1; i*i <= b; i++) {
if(b%i) continue;
if(i*i==b) continue;
int z = (b / i + i);
int w = (b / i - i);
if(1 <= z && z <= n && 1 <= w && w <= n) {
ans_xy++;
}
}
}
else {
for(int i = 1; i*i <= a; i += 2) {
if(a%i) continue;
if(i*i==a) continue;
int z = (a / i + i) / 2;
int w = (a / i - i) / 2;
if(1 <= z && z <= n && 1 <= w && w <= n) {
ans_xy++;
}
}
}
if(x == y) ans += ans_xy;
else ans += ans_xy * 2;
}
}
cout << ans << endl;
return 0;
}