結果

問題 No.800 四平方定理
ユーザー ningenMeningenMe
提出日時 2019-03-17 23:44:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,732 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 91,844 KB
実行使用メモリ 34,336 KB
最終ジャッジ日時 2023-09-22 15:27:39
合計ジャッジ時間 2,935 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
34,068 KB
testcase_01 AC 12 ms
34,208 KB
testcase_02 AC 11 ms
34,008 KB
testcase_03 AC 11 ms
34,232 KB
testcase_04 AC 11 ms
34,280 KB
testcase_05 AC 11 ms
34,184 KB
testcase_06 AC 12 ms
34,032 KB
testcase_07 AC 11 ms
34,136 KB
testcase_08 AC 11 ms
34,204 KB
testcase_09 AC 11 ms
34,196 KB
testcase_10 AC 25 ms
34,108 KB
testcase_11 AC 27 ms
34,280 KB
testcase_12 AC 27 ms
34,192 KB
testcase_13 AC 25 ms
34,260 KB
testcase_14 AC 26 ms
33,996 KB
testcase_15 AC 27 ms
34,148 KB
testcase_16 AC 28 ms
34,248 KB
testcase_17 AC 27 ms
34,260 KB
testcase_18 AC 29 ms
34,188 KB
testcase_19 AC 29 ms
34,136 KB
testcase_20 AC 12 ms
34,108 KB
testcase_21 AC 10 ms
33,972 KB
testcase_22 AC 28 ms
34,036 KB
testcase_23 AC 59 ms
34,036 KB
testcase_24 AC 56 ms
34,192 KB
testcase_25 AC 58 ms
34,036 KB
testcase_26 AC 11 ms
34,212 KB
testcase_27 AC 10 ms
34,064 KB
testcase_28 AC 55 ms
34,336 KB
testcase_29 AC 58 ms
34,112 KB
testcase_30 AC 55 ms
34,040 KB
testcase_31 AC 50 ms
34,204 KB
testcase_32 AC 58 ms
34,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	V<int> c(8000000 + 1);
	ll N,D; cin >> N >> D;
	for(int x = 1; x <= N; ++x){
		for(int y = 1; y <= N; ++y){
			c[x*x + y*y]++;
		}
	}

	ll ans = 0;
	for(int w = 1; w <= N; ++w){
		for (int z = 1; z <= N; ++z) {
			if (w*w - z*z + D >= 0) ans += c[w*w - z*z + D];
		}
	}
	cout << ans << endl;
	return 0;
}

0