結果

問題 No.6 使いものにならないハッシュ
ユーザー HimatsubushinHimatsubushin
提出日時 2019-12-24 10:53:31
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,744 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 65,148 KB
実行使用メモリ 22,896 KB
最終ジャッジ日時 2023-10-14 23:21:04
合計ジャッジ時間 4,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,756 KB
testcase_01 AC 54 ms
20,672 KB
testcase_02 AC 61 ms
20,856 KB
testcase_03 AC 54 ms
18,744 KB
testcase_04 AC 57 ms
22,868 KB
testcase_05 AC 55 ms
20,648 KB
testcase_06 AC 58 ms
20,836 KB
testcase_07 AC 57 ms
20,788 KB
testcase_08 AC 58 ms
20,720 KB
testcase_09 AC 58 ms
20,648 KB
testcase_10 WA -
testcase_11 AC 56 ms
20,688 KB
testcase_12 AC 59 ms
20,784 KB
testcase_13 AC 56 ms
20,616 KB
testcase_14 AC 57 ms
20,764 KB
testcase_15 AC 58 ms
18,704 KB
testcase_16 AC 57 ms
20,616 KB
testcase_17 AC 60 ms
20,680 KB
testcase_18 AC 63 ms
22,704 KB
testcase_19 AC 60 ms
20,656 KB
testcase_20 AC 60 ms
22,648 KB
testcase_21 AC 56 ms
20,800 KB
testcase_22 AC 60 ms
20,756 KB
testcase_23 AC 60 ms
20,680 KB
testcase_24 AC 59 ms
20,592 KB
testcase_25 AC 58 ms
22,712 KB
testcase_26 AC 61 ms
20,752 KB
testcase_27 AC 59 ms
20,660 KB
testcase_28 AC 58 ms
20,660 KB
testcase_29 AC 61 ms
22,896 KB
testcase_30 AC 60 ms
20,680 KB
testcase_31 AC 60 ms
20,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;

namespace No006_使いものにならないハッシュ
{
    class Program
    {
        static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());
            bool[] numbers = new bool[n + 1];
            var prime = new List<int>();
            int start = 0, max = 0;

            if (k <= 2)
                prime.Add(2);

            for (int i = 3; i <= n; i += 2)
                numbers[i] = true;

            for (int i = 3; i < n; i += 2)
                for (int j = 2; i * j <= n; j++)
                    numbers[i * j] = false;

            for (int i = k + 1 - k % 2; i <= n; i += 2)
                if (numbers[i])
                    prime.Add(i);

            for (int i = 0; i < prime.Count - 1; i++)
            {
                bool[] checker = new bool[10];
                int count = 1;

                checker[hash(prime[i])] = true;
                for (int j = 1; j < 11 && i + j < prime.Count; j++)
                {
                    int value = hash(prime[i + j]);

                    if (!checker[value])
                    {
                        checker[value] = true;
                        count++;
                    }
                    else
                        break;
                }
                if (max <= count)
                {
                    max = count;
                    start = prime[i];
                }
            }

            Console.WriteLine(start);
        }

        static int hash(int number)
        {
            while (number >= 10)
                number = number / 10 + number % 10;

            return number;
        }
    }
}
0