結果

問題 No.800 四平方定理
コンテスト
ユーザー Artemis2718
提出日時 2019-04-27 11:23:49
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 641 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 157 ms
コンパイル使用メモリ 40,004 KB
最終ジャッジ日時 2026-02-22 03:13:35
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int n,d;
    int x,y,z,w;
    int k;
    int ans = 0;
    int *cnt1,*cnt2;

    cnt1 = (int *)malloc(sizeof(int)*8000000);
    cnt2 = (int *)malloc(sizeof(int)*8000000);
    scanf("%d%d",&n,&d);
    for(x=1;x<=n;x++){
        for(y=1;y<=n;y++){
            cnt1[(x*x+y*y)]++;
        }
    }
    for(z=1;z<=n;z++){
        for(w=1;w<=n;w++){
            if((w*w-z*z+d)>=0){
                cnt2[(w*w-z*z+d)]++;
            }
        }
    }
    for(k=1;k<=8000000;k++){
        ans += cnt1[k]*cnt2[k];
    }
    printf("%d\n",ans);
    free(cnt1);
    free(cnt2);
    return 0;
}
0