結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-04-27 11:20:33 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 640 bytes | 
| コンパイル時間 | 336 ms | 
| コンパイル使用メモリ | 30,464 KB | 
| 実行使用メモリ | 31,744 KB | 
| 最終ジャッジ日時 | 2024-11-27 12:06:43 | 
| 合計ジャッジ時間 | 4,253 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 RE * 8 | 
ソースコード
#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)*5000000);
    cnt2 = (int *)malloc(sizeof(int)*5000000);
    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<=5000000;k++){
        ans += cnt1[k]*cnt2[k];
    }
    printf("%d\n",ans);
    free(cnt1);
    free(cnt2);
    return 0;
}