結果

問題 No.800 四平方定理
ユーザー jupiro_jupi
提出日時 2019-06-14 22:04:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,553 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 1,195 ms
コンパイル使用メモリ 99,612 KB
実行使用メモリ 37,592 KB
最終ジャッジ日時 2024-11-14 05:57:37
合計ジャッジ時間 20,956 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <fstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

char ToUpper(char cX) { return toupper(cX); }
char Tolower(char cX) { return tolower(cX); }


const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
const long long MAX = 500000LL;
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
using T = tuple<ll, ll, ll>;


int main()
{
	ll N, D;
	cin >> N >> D;
	vector<ll> sum1;
	for (ll x = 1; x <= N; x++) {
		for (ll y = 1; y <= N; y++) {
			sum1.push_back(x * x + y * y);
		}
	}
	sort(sum1.begin(), sum1.end());
	ll res = 0;
	for (ll z = 1; z <= N; z++) {
		for (ll w = 1; w <= N; w++) {
			ll temp = w * w + D - z * z;
			res += upper_bound(sum1.begin(), sum1.end(), temp) - lower_bound(sum1.begin(), sum1.end(), temp);
		}
	}

	cout << res << endl;
	return 0;
}

0