結果
| 問題 | 
                            No.800 四平方定理
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-03-17 22:22:58 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,092 ms / 2,000 ms | 
| コード長 | 1,953 bytes | 
| コンパイル時間 | 776 ms | 
| コンパイル使用メモリ | 114,472 KB | 
| 実行使用メモリ | 87,504 KB | 
| 最終ジャッジ日時 | 2024-07-08 00:09:38 | 
| 合計ジャッジ時間 | 15,089 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        long D = NextLong();
        Dictionary<long, long> xy = new Dictionary<long, long>();
        for (int x = 1; x <= N; x++)
            for (int y = x; y <= N; y++)
            {
                long c = (long)Math.Pow(x, 2) + (long)Math.Pow(y, 2);
                if (!xy.ContainsKey(c)) xy[c] = 0;
                if (x != y) xy[c] += 2;
                else xy[c]++;
            }
        long ans = 0;
        for (int w = 1; w <= N; w++)
        {
            for (int z = 1; z <= N; z++)
            {
                long key = D + (long)Math.Pow(w, 2) - (long)Math.Pow(z, 2);
                if (key <= 0) break;
                if (xy.ContainsKey(key)) ans += xy[key];
            }
        }
        Console.WriteLine(ans);
    }
}
public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}