結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 18 ms
65,968 KB
testcase_01 AC 18 ms
66,000 KB
testcase_02 AC 18 ms
65,876 KB
testcase_03 AC 16 ms
65,968 KB
testcase_04 AC 17 ms
65,824 KB
testcase_05 AC 18 ms
65,888 KB
testcase_06 AC 17 ms
65,908 KB
testcase_07 AC 17 ms
65,936 KB
testcase_08 AC 18 ms
65,924 KB
testcase_09 AC 17 ms
65,888 KB
testcase_10 AC 41 ms
65,872 KB
testcase_11 AC 40 ms
65,936 KB
testcase_12 AC 41 ms
65,936 KB
testcase_13 AC 37 ms
65,892 KB
testcase_14 AC 39 ms
65,944 KB
testcase_15 AC 39 ms
66,004 KB
testcase_16 AC 39 ms
65,892 KB
testcase_17 AC 38 ms
65,980 KB
testcase_18 AC 44 ms
65,876 KB
testcase_19 AC 42 ms
65,968 KB
testcase_20 AC 18 ms
65,840 KB
testcase_21 AC 16 ms
65,920 KB
testcase_22 AC 44 ms
65,992 KB
testcase_23 AC 70 ms
65,928 KB
testcase_24 AC 63 ms
65,824 KB
testcase_25 AC 66 ms
65,876 KB
testcase_26 AC 17 ms
65,968 KB
testcase_27 AC 16 ms
65,920 KB
testcase_28 AC 66 ms
65,928 KB
testcase_29 AC 67 ms
65,940 KB
testcase_30 AC 65 ms
66,008 KB
testcase_31 AC 60 ms
65,892 KB
testcase_32 AC 65 ms
65,876 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