結果

問題 No.800 四平方定理
ユーザー chocoruskchocorusk
提出日時 2019-03-17 21:25:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,372 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 94,188 KB
実行使用メモリ 66,140 KB
最終ジャッジ日時 2023-09-22 03:29:49
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
65,972 KB
testcase_01 AC 20 ms
65,884 KB
testcase_02 AC 19 ms
65,832 KB
testcase_03 AC 21 ms
66,120 KB
testcase_04 AC 20 ms
66,008 KB
testcase_05 AC 19 ms
66,044 KB
testcase_06 AC 20 ms
65,840 KB
testcase_07 AC 19 ms
65,840 KB
testcase_08 AC 21 ms
65,848 KB
testcase_09 AC 20 ms
65,832 KB
testcase_10 AC 56 ms
65,828 KB
testcase_11 AC 59 ms
65,968 KB
testcase_12 AC 58 ms
66,000 KB
testcase_13 AC 52 ms
65,884 KB
testcase_14 AC 56 ms
65,836 KB
testcase_15 AC 59 ms
65,888 KB
testcase_16 AC 53 ms
65,836 KB
testcase_17 AC 55 ms
65,844 KB
testcase_18 AC 63 ms
65,884 KB
testcase_19 AC 63 ms
66,008 KB
testcase_20 AC 19 ms
66,016 KB
testcase_21 AC 19 ms
65,840 KB
testcase_22 AC 62 ms
65,840 KB
testcase_23 AC 107 ms
65,904 KB
testcase_24 AC 96 ms
65,832 KB
testcase_25 AC 106 ms
66,140 KB
testcase_26 AC 20 ms
65,908 KB
testcase_27 AC 19 ms
65,840 KB
testcase_28 AC 95 ms
65,888 KB
testcase_29 AC 101 ms
65,844 KB
testcase_30 AC 94 ms
66,004 KB
testcase_31 AC 89 ms
65,840 KB
testcase_32 AC 95 ms
65,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <utility>
#include <functional>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[1000001], invf[1000001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(x<y) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int n, d; cin>>n>>d;
    ll ct[8000001]={};
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            ct[i*i+j*j]++;
        }
    }
    ll ans=0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            int x=i*i-j*j+d;
            if(x>0 && x<=2*n*n){
                ans+=ct[x];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
0