結果

問題 No.800 四平方定理
ユーザー NaruYNaruY
提出日時 2019-03-18 15:20:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 2,239 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 163,556 KB
実行使用メモリ 108,016 KB
最終ジャッジ日時 2023-09-25 12:29:19
合計ジャッジ時間 4,891 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,752 KB
testcase_01 AC 13 ms
8,064 KB
testcase_02 AC 13 ms
5,808 KB
testcase_03 AC 13 ms
5,900 KB
testcase_04 AC 13 ms
5,876 KB
testcase_05 AC 13 ms
5,936 KB
testcase_06 AC 13 ms
8,168 KB
testcase_07 AC 13 ms
8,476 KB
testcase_08 AC 14 ms
10,120 KB
testcase_09 AC 14 ms
8,148 KB
testcase_10 AC 62 ms
56,544 KB
testcase_11 AC 68 ms
60,628 KB
testcase_12 AC 67 ms
62,840 KB
testcase_13 AC 63 ms
54,580 KB
testcase_14 AC 63 ms
58,604 KB
testcase_15 AC 68 ms
62,700 KB
testcase_16 AC 64 ms
58,608 KB
testcase_17 AC 65 ms
58,584 KB
testcase_18 AC 73 ms
66,832 KB
testcase_19 AC 73 ms
66,960 KB
testcase_20 AC 12 ms
5,440 KB
testcase_21 AC 12 ms
5,464 KB
testcase_22 AC 73 ms
66,820 KB
testcase_23 AC 134 ms
107,812 KB
testcase_24 AC 119 ms
99,620 KB
testcase_25 AC 135 ms
108,016 KB
testcase_26 AC 12 ms
5,368 KB
testcase_27 AC 13 ms
7,480 KB
testcase_28 AC 120 ms
99,616 KB
testcase_29 AC 126 ms
103,688 KB
testcase_30 AC 118 ms
99,584 KB
testcase_31 AC 109 ms
93,588 KB
testcase_32 AC 118 ms
99,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
   static ll count1[2*2000*2000+10]={};
   static ll count2[2*2000*2000+10]={};
   int N; cin >> N;
   ll D; cin >> D;

   for(ll x = 1; x <= N; x++){
       for(ll y = 1; y <= N ; y++){
           count1[x*x+y*y]++;
       }
   }

    for(ll z = 1; z <= N; z++){
        for(ll w = 1; w <= N ; w++){
            if(w*w-z*z+D < 0) continue;
            count2[w*w-z*z+D]++;
        }
    }

    ll ans = 0;
    FORq(i,0,8000001){
        ans += count1[i] * count2[i];
    }

    cout << ans << "\n";

}




0