結果

問題 No.800 四平方定理
ユーザー kenken714kenken714
提出日時 2019-03-17 22:12:14
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,126 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 78,480 KB
実行使用メモリ 46,504 KB
最終ジャッジ日時 2023-09-22 07:02:55
合計ジャッジ時間 4,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
46,504 KB
testcase_01 AC 70 ms
42,132 KB
testcase_02 AC 50 ms
42,188 KB
testcase_03 AC 55 ms
42,188 KB
testcase_04 AC 42 ms
41,908 KB
testcase_05 AC 50 ms
42,128 KB
testcase_06 AC 90 ms
42,048 KB
testcase_07 AC 70 ms
42,144 KB
testcase_08 AC 116 ms
42,220 KB
testcase_09 AC 78 ms
42,108 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, d, ans = 0;
vector<ll> memo(5000000, -1);

ll s(ll a) {
	if (a < 0)a *= -1;
	if (memo[a] != -1)return memo[a];
	if (a == 0)return n;
	ll res = 0;
	for (ll i = 1; i <= min(n, (ll)sqrt(a)); i++)
	{
		if (a % i == 0) {
			if (a / i <= i)break;
			if (abs(i - a / i) % 2 == 0 and i <= n and i + abs(i - a / i) / 2 <= n)res++;
		}
	}
	memo[a] = res;
	return res;
}
int main() {
	cin >> n >> d;
	REPO(i, n) {
		REPO(j, n) {
			ll now = i * i + j * j - d;
			ans += s(now);
		}
	}
	cout << ans << endl;
}

0