結果

問題 No.800 四平方定理
ユーザー Artemis2718
提出日時 2019-04-27 11:23:49
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 30,336 KB
実行使用メモリ 51,968 KB
最終ジャッジ日時 2024-11-27 12:10:41
合計ジャッジ時間 2,489 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#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