結果

問題 No.800 四平方定理
コンテスト
ユーザー vjudge1
提出日時 2026-02-05 20:09:35
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,465 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,854 ms
コンパイル使用メモリ 203,212 KB
実行使用メモリ 65,268 KB
最終ジャッジ日時 2026-02-05 20:09:43
合計ジャッジ時間 5,142 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
typedef long long ll;
typedef long double ld;
typedef int praise_long_long;
namespace io {
    using namespace std;
    inline ll read () {
        char x=getchar();
        ll ans=0,f=1;
        while (x<'0'||x>'9') {
            if (x=='-') {
                f*=(-1);
            }
            x=getchar();
        }
        while (x>='0'&&x<='9') {
            ans*=10;
            ans+=(x-'0');
            x=getchar();
        }
        return ans*f;
    }
    void print (ll x) {
        if (x<0) {
            x=-x;
            putchar('-');
        }
        if (x>=10) {
            print(x/10);
        }
        putchar(x%10+'0');
    }
}
using namespace io;
const ll N=2e3+5,mod=1e9+7,inf=2e18;
const ld eps=1e-6;
ll n,k,a[N],num[N*N*2],ans;
inline void solve () {
    n=read(),k=read();
    for (ll i=1;i<=n;i++) {
        a[i]=i*i;
    }
    for (ll i=1;i<=n;i++) {
        num[a[i]*2]++;
        for (ll j=i+1;j<=n;j++) {
            num[a[i]+a[j]]+=2;
        }
    }
    for (ll a=1;a<=n;a++) {
        for (ll d=1;d<=n;d++) {
            ll kl=d*d+k-a*a;
            if (kl<0) {
                continue;
            }
            ans+=num[kl];
        }
    }
    print(ans);
}
praise_long_long main () {
    // freopen("alive.in","r",stdin);
    // freopen("alive.out","w",stdout);
    ll T=1;
    // T=read();
    while (T--) {
        solve();
    }
    return 0;
}
/**/
0