結果

問題 No.800 四平方定理
ユーザー pazzle1230pazzle1230
提出日時 2019-03-29 01:11:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 3,824 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 168,936 KB
実行使用メモリ 190,748 KB
最終ジャッジ日時 2024-04-23 13:50:32
合計ジャッジ時間 6,378 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
190,448 KB
testcase_01 AC 79 ms
190,604 KB
testcase_02 AC 80 ms
190,660 KB
testcase_03 AC 78 ms
190,508 KB
testcase_04 AC 80 ms
190,464 KB
testcase_05 AC 79 ms
190,540 KB
testcase_06 AC 79 ms
190,452 KB
testcase_07 AC 79 ms
190,684 KB
testcase_08 AC 79 ms
190,452 KB
testcase_09 AC 78 ms
190,444 KB
testcase_10 AC 106 ms
190,432 KB
testcase_11 AC 109 ms
190,532 KB
testcase_12 AC 111 ms
190,664 KB
testcase_13 AC 102 ms
190,516 KB
testcase_14 AC 106 ms
190,508 KB
testcase_15 AC 111 ms
190,568 KB
testcase_16 AC 107 ms
190,624 KB
testcase_17 AC 111 ms
190,488 KB
testcase_18 AC 118 ms
190,444 KB
testcase_19 AC 116 ms
190,428 KB
testcase_20 AC 78 ms
190,748 KB
testcase_21 AC 78 ms
190,444 KB
testcase_22 AC 115 ms
190,600 KB
testcase_23 AC 156 ms
190,456 KB
testcase_24 AC 141 ms
190,584 KB
testcase_25 AC 157 ms
190,628 KB
testcase_26 AC 77 ms
190,600 KB
testcase_27 AC 78 ms
190,472 KB
testcase_28 AC 141 ms
190,540 KB
testcase_29 AC 145 ms
190,452 KB
testcase_30 AC 142 ms
190,604 KB
testcase_31 AC 134 ms
190,504 KB
testcase_32 AC 141 ms
190,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std; 
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

template<::std::uint_fast64_t mod>
class ModInt{
private:
	using value_type = ::std::uint_fast64_t;
	value_type n;
public:
	ModInt() : n(0) {}
	ModInt(value_type n_) : n(n_ % mod) {}
	ModInt(const ModInt& m) : n(m.n) {}

	template<typename T>
	explicit operator T() const { return static_cast<T>(n); }
	value_type get() const { return n; }

	friend ::std::ostream& operator<<(::std::ostream &os, const ModInt<mod> &a) {
		return os << a.n;
	}

	friend ::std::istream& operator>>(::std::istream &is, ModInt<mod> &a) {
		value_type x;
		is >> x;
		a = ModInt<mod>(x);
		return is;
	}

	bool operator==(const ModInt& m) const { return n == m.n; }
	bool operator!=(const ModInt& m) const { return n != m.n; }
	ModInt& operator*=(const ModInt& m){ n = n * m.n % mod; return *this; }

	ModInt pow(value_type b) const{
		ModInt ans = 1, m = ModInt(*this);
		while(b){
			if(b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}

	ModInt inv() const { return (*this).pow(mod-2); }
	ModInt& operator+=(const ModInt& m){ n += m.n; n = (n < mod ? n : n - mod); return *this; }
	ModInt& operator-=(const ModInt& m){ n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	ModInt& operator/=(const ModInt& m){ *this *= m.inv(); return *this; }
	ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
	ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
	ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
	ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
	ModInt& operator++(){ n += 1; return *this; }
	ModInt& operator--(){ n -= 1; return *this; }
	ModInt operator++(int){
		ModInt old(n);
		n += 1;
		return old;
	}
	ModInt operator--(int){
		ModInt old(n);
		n -= 1;
		return old;
	}
	ModInt operator-() const { return ModInt(mod-n); }
};

template<::std::size_t size, ::std::uint_fast64_t mod=1000000007>
class Factorial{
private:
	using value_type = ModInt<mod>;
	::std::vector<value_type> fact, inv;
public:
	Factorial() : fact(size+1, 1), inv(size+1, 1){
		for(::std::size_t i = 1; i <= size; ++i){
			fact[i] = fact[i-1] * value_type(i);
			inv[i] = fact[i].inv();
		}
	}

	value_type comb(::std::int64_t a, ::std::int64_t b){
		assert(a >= b);
		assert(b >= 0);
		return fact[a]*inv[b]*inv[a-b];
	}

	value_type& operator[](::std::size_t k){ return fact[k]; }
};

const int64 mod = 1e9+7;
using Mint = ModInt<mod>;

int main(void) {
	auto cnt = make_v<int64>(2, 2*2000*2000+1);
	int64 N, D;
	cin >> N >> D;
	FOR(i, 1, N+1) {
		FOR(j, 1, N+1) {
			cnt[0][i*i+j*j]++;
			if (i*i-j*j+D >= 0 && i*i-j*j+D < cnt[0].size())
				cnt[1][i*i-j*j+D]++;
		}
	}
	int64 res= 0;
	FOR(i, 1, 2*2000*2000+1) {
		res += cnt[0][i]*cnt[1][i];
	}
	cout << res << endl;
}
0