結果

問題 No.800 四平方定理
ユーザー kenken714
提出日時 2019-03-17 22:09:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,045 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 81,704 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2024-07-07 23:29:51
合計ジャッジ時間 5,450 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 10 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

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;

ll s(ll a) {
	if (a == 0)return n;
	if (a < 0)a *= -1;
	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++;
		}
	}
	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