結果
問題 | No.800 四平方定理 |
ユーザー | startcpp |
提出日時 | 2019-03-17 22:38:22 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 138 ms / 2,000 ms |
コード長 | 530 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 54,228 KB |
実行使用メモリ | 103,424 KB |
最終ジャッジ日時 | 2024-07-08 00:47:54 |
合計ジャッジ時間 | 2,879 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream> #define int long long using namespace std; int cnt1[8000001]; //x^2 + y^2 int cnt2[8000001]; //z^2 - w^2 + D int n, d; signed main() { int i, j; cin >> n >> d; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cnt1[i * i + j * j]++; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { int x = i * i - j * j + d; if (0 <= x && x <= 2 * n * n) { cnt2[x]++; } } } int ans = 0; for (i = 0; i <= 2 * n * n; i++) ans += cnt1[i] * cnt2[i]; cout << ans << endl; return 0; }