結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-17 21:46:48 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 1,691 ms / 2,000 ms |
| コード長 | 1,848 bytes |
| コンパイル時間 | 807 ms |
| コンパイル使用メモリ | 106,624 KB |
| 実行使用メモリ | 76,056 KB |
| 最終ジャッジ日時 | 2024-07-07 21:37:46 |
| 合計ジャッジ時間 | 24,946 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 = 1; y <= N; y++)
{
long c = (long)Math.Pow(x, 2) + (long)Math.Pow(y, 2);
if (!xy.ContainsKey(c)) xy[c] = 0;
xy[c]++;
}
long ans = 0;
for (int z = 1; z <= N; z++)
for (int w = 1; w <= N; w++)
{
long c = (long)Math.Pow(z, 2) - (long)Math.Pow(w, 2);
if (xy.ContainsKey(D - c)) ans += xy[D - c];
}
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(); }
}