結果

問題 No.800 四平方定理
ユーザー pekempeypekempey
提出日時 2019-03-17 21:27:21
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 500 ms
使用メモリ 54,208 KB
最終ジャッジ日時 2023-02-11 04:02:06
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 9 ms
6,948 KB
testcase_01 AC 9 ms
5,800 KB
testcase_02 AC 9 ms
5,636 KB
testcase_03 AC 9 ms
5,764 KB
testcase_04 AC 8 ms
5,716 KB
testcase_05 AC 9 ms
6,948 KB
testcase_06 AC 9 ms
6,948 KB
testcase_07 AC 9 ms
6,948 KB
testcase_08 AC 9 ms
6,196 KB
testcase_09 AC 9 ms
5,844 KB
testcase_10 AC 25 ms
28,764 KB
testcase_11 AC 23 ms
30,820 KB
testcase_12 AC 25 ms
31,596 KB
testcase_13 AC 22 ms
27,976 KB
testcase_14 AC 23 ms
29,872 KB
testcase_15 AC 24 ms
31,708 KB
testcase_16 AC 25 ms
30,128 KB
testcase_17 AC 23 ms
30,032 KB
testcase_18 AC 26 ms
33,848 KB
testcase_19 AC 27 ms
33,968 KB
testcase_20 AC 8 ms
5,492 KB
testcase_21 AC 8 ms
5,472 KB
testcase_22 AC 27 ms
34,036 KB
testcase_23 AC 42 ms
54,208 KB
testcase_24 AC 39 ms
50,380 KB
testcase_25 AC 45 ms
54,152 KB
testcase_26 AC 9 ms
6,952 KB
testcase_27 AC 9 ms
7,468 KB
testcase_28 AC 39 ms
49,980 KB
testcase_29 AC 42 ms
52,064 KB
testcase_30 AC 38 ms
50,152 KB
testcase_31 AC 37 ms
46,964 KB
testcase_32 AC 40 ms
50,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int C1[2000*2000 + 2000*2000 + 1];
int C2[2000*2000 + 2000*2000 + 1];

int main() {
  int N, D;
  cin >> N >> D;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      C1[i*i + j*j]++;
      int k = i*i - j*j + D;
      if (0 <= k && k <= 2000*2000 + 2000*2000) {
        C2[k]++;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= 2000*2000 + 2000*2000; i++) {
    ans += C1[i] * C2[i];
  }
  cout << ans << endl;
}
0