結果

問題 No.800 四平方定理
ユーザー oshiborioshibori
提出日時 2019-03-18 05:33:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,767 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 165,408 KB
実行使用メモリ 65,248 KB
最終ジャッジ日時 2023-09-22 22:50:43
合計ジャッジ時間 3,791 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,528 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,408 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,716 KB
testcase_07 AC 3 ms
4,456 KB
testcase_08 AC 3 ms
4,840 KB
testcase_09 AC 2 ms
4,612 KB
testcase_10 AC 32 ms
36,088 KB
testcase_11 AC 31 ms
38,228 KB
testcase_12 AC 34 ms
38,132 KB
testcase_13 AC 31 ms
36,188 KB
testcase_14 AC 32 ms
38,280 KB
testcase_15 AC 32 ms
38,124 KB
testcase_16 AC 32 ms
40,320 KB
testcase_17 AC 32 ms
40,192 KB
testcase_18 AC 38 ms
40,280 KB
testcase_19 AC 37 ms
40,188 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 37 ms
40,332 KB
testcase_23 AC 68 ms
65,248 KB
testcase_24 AC 61 ms
65,016 KB
testcase_25 AC 69 ms
64,936 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 59 ms
65,028 KB
testcase_29 AC 79 ms
64,924 KB
testcase_30 AC 60 ms
64,888 KB
testcase_31 AC 53 ms
62,744 KB
testcase_32 AC 60 ms
64,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
int mp[8 * 1000001];
signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, D; cin >> N >> D;

	rep(i, 1, N + 1)rep(j, 1, N + 1) {
		int x = i * i + j * j;
		mp[x]++;
	}
	ll ans = 0;
	rep(i, 1, N + 1)rep(j, 1, N + 1) {
		int x = i * i - j * j + D;

		if (x >= 0)
			ans += mp[x];
	}
	cout << ans << endl;

	return 0;
}
0