結果
問題 | No.800 四平方定理 |
ユーザー |
|
提出日時 | 2020-08-01 22:44:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 663 bytes |
コンパイル時間 | 821 ms |
コンパイル使用メモリ | 71,664 KB |
最終ジャッジ日時 | 2025-01-12 12:55:21 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> using lint = long long; constexpr int N = 2000 * 2000 * 2; void solve() { int n, d; std::cin >> n >> d; std::vector<lint> cnt(N + 1, 0); for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { ++cnt[x * x + y * y]; } } lint ans = 0; for (int z = 1; z <= n; ++z) { for (int w = 1; w <= n; ++w) { lint rhs = w * w - z * z + d; if (0 <= rhs && rhs <= N) ans += cnt[rhs]; } } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }