結果

問題 No.1140 EXPotentiaLLL!
ユーザー bluemeganebluemegane
提出日時 2020-09-08 20:06:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,857 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 63,916 KB
実行使用メモリ 53,824 KB
最終ジャッジ日時 2023-08-20 05:42:47
合計ジャッジ時間 27,129 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,813 ms
49,764 KB
testcase_01 AC 1,845 ms
53,824 KB
testcase_02 AC 1,812 ms
49,636 KB
testcase_03 AC 1,719 ms
50,148 KB
testcase_04 AC 1,613 ms
48,436 KB
testcase_05 AC 1,857 ms
51,360 KB
testcase_06 AC 1,787 ms
53,248 KB
testcase_07 AC 1,852 ms
49,788 KB
testcase_08 AC 1,299 ms
39,412 KB
testcase_09 AC 1,291 ms
39,568 KB
testcase_10 AC 1,292 ms
39,480 KB
testcase_11 AC 1,288 ms
39,556 KB
testcase_12 AC 1,286 ms
39,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        var T = int.Parse(Console.ReadLine().Trim());
        var c = new bool[5000001];
        GeneratePrime(c);
        var ans = new int[T];
        for (int i = 0; i < T; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = long.Parse(line[0]);
            var p = int.Parse(line[1]);
            if (!c[p]) ans[i] = -1;
            else ans[i] = a % p == 0 ? 0 : 1;
        }
        Console.WriteLine(string.Join("\n", ans));
    }

    static void GeneratePrime(bool[] p)
    {
        int prime;
        var m = p.Length;
        var sqrtMax = Math.Sqrt(m);
        var searchList = Enumerable.Range(2, m - 1).ToList();
        do
        {
            prime = searchList.First();
            p[prime] = true;
            searchList.RemoveAll(n => n % prime == 0);
        }
        while (prime < sqrtMax);
        foreach (var x in searchList)
            p[x] = true;
    }

}
0