結果

問題 No.800 四平方定理
ユーザー ark27
提出日時 2019-07-26 11:40:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 166,808 KB
実行使用メモリ 128,524 KB
最終ジャッジ日時 2024-07-02 06:24:52
合計ジャッジ時間 6,793 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
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;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

int main(){
	ll n,d;
	cin >> n >> d;
	ll c1[8000010],c2[8000010];
	FOR(i,8000005){
		c1[i]=0;
		c2[i]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			c1[i*i+j*j]++;
			if(i*i-j*j+d<0)continue;
			c2[i*i-j*j+d]++;
		}
	}
	ll ans=0;
	for(int i=1;i<=8000005;i++){
		ans+=c1[i]*c2[i];
	}
	cout << ans << endl;
}
0