結果

問題 No.152 貯金箱の消失
ユーザー mbanmban
提出日時 2017-01-13 09:01:10
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 964 ms / 5,000 ms
コード長 2,263 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 106,436 KB
実行使用メモリ 27,028 KB
最終ジャッジ日時 2023-08-23 08:49:47
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
18,764 KB
testcase_01 AC 57 ms
20,800 KB
testcase_02 AC 57 ms
20,712 KB
testcase_03 AC 57 ms
24,920 KB
testcase_04 AC 65 ms
22,772 KB
testcase_05 AC 66 ms
22,916 KB
testcase_06 AC 75 ms
26,880 KB
testcase_07 AC 189 ms
26,856 KB
testcase_08 AC 951 ms
26,924 KB
testcase_09 AC 964 ms
27,028 KB
testcase_10 AC 763 ms
26,872 KB
testcase_11 AC 438 ms
24,964 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static private Magatro M = new Magatro();
    static private void Main(string[]args)
    {
        M.Scan();
        M.Solve();
    }
}

public class Scanner
{
    private string[] S;
    private int Index;
    private char Separator;

    public Scanner(char separator = ' ')
    {
        Index = 0;
        Separator = separator;
    }

    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}

public class Magatro
{
    private int L;

    public void Scan()
    {
        Scanner sc = new Scanner();
        L = sc.NextInt();
    }

    public void Solve()
    {
        int loop = (int)Math.Sqrt(L);
        int cnt = 0;
        for(int i = 2; i <= loop; i++)
        {
            for(int j = 1; j < i; j++)
            {
                int a = i * i - j * j;
                int b = 2 * i * j;
                int c = i * i + j * j;
                if (Gcd(a, b, c) == 1&&a+b+c<=L/4) cnt++;
            }
        }
        Console.WriteLine(cnt);
    }

    private int Gcd(params int[] n)
    {
        int result = n[0];
        for(int i = 1; i < n.Length; i++)
        {
            result = Gcd(result, n[i]);
        }
        return result;
    }
    private int Gcd(int a,int b)
    {
        if (a < b)
        {
            Swap(ref a, ref b);
        }
        int r = a % b;
        while (r > 0)
        {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }
    private void Swap(ref int a,ref int b)
    {
        int temp = a;
        a = b;
        b = temp;
    }
}
0