結果

問題 No.136 Yet Another GCD Problem
ユーザー syoken_desukasyoken_desuka
提出日時 2015-02-27 13:54:23
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 4,217 bytes
コンパイル時間 2,576 ms
コンパイル使用メモリ 106,100 KB
実行使用メモリ 25,444 KB
最終ジャッジ日時 2023-09-06 03:47:07
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
25,252 KB
testcase_01 AC 67 ms
23,220 KB
testcase_02 AC 66 ms
25,148 KB
testcase_03 AC 66 ms
21,328 KB
testcase_04 AC 65 ms
23,272 KB
testcase_05 AC 65 ms
23,232 KB
testcase_06 AC 65 ms
23,176 KB
testcase_07 AC 65 ms
21,328 KB
testcase_08 AC 66 ms
23,172 KB
testcase_09 AC 66 ms
25,064 KB
testcase_10 AC 64 ms
21,276 KB
testcase_11 AC 66 ms
25,312 KB
testcase_12 AC 66 ms
23,084 KB
testcase_13 AC 66 ms
23,080 KB
testcase_14 AC 66 ms
23,316 KB
testcase_15 AC 65 ms
23,156 KB
testcase_16 AC 66 ms
25,288 KB
testcase_17 AC 67 ms
25,136 KB
testcase_18 AC 65 ms
23,124 KB
testcase_19 AC 64 ms
23,280 KB
testcase_20 AC 66 ms
25,132 KB
testcase_21 AC 65 ms
23,316 KB
testcase_22 AC 65 ms
23,176 KB
testcase_23 AC 66 ms
23,264 KB
testcase_24 AC 66 ms
23,244 KB
testcase_25 AC 66 ms
23,252 KB
testcase_26 AC 67 ms
23,032 KB
testcase_27 AC 65 ms
23,316 KB
testcase_28 AC 65 ms
23,084 KB
testcase_29 AC 65 ms
23,184 KB
testcase_30 AC 65 ms
23,272 KB
testcase_31 AC 64 ms
25,228 KB
testcase_32 AC 65 ms
25,444 KB
testcase_33 AC 70 ms
23,256 KB
testcase_34 AC 67 ms
25,236 KB
testcase_35 AC 66 ms
23,272 KB
testcase_36 AC 66 ms
23,304 KB
testcase_37 AC 67 ms
25,136 KB
testcase_38 AC 66 ms
23,184 KB
testcase_39 AC 66 ms
23,100 KB
testcase_40 AC 65 ms
23,280 KB
testcase_41 AC 65 ms
25,188 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.Generic;
using System.Text;
using sc = Scanner;
using System.Collections;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        Solve();
#if DEBUG
        Console.WriteLine("終了するにはなにかキーを押して下さい...");
        Console.ReadKey();
#endif

    }

    static void Solve()
    {
        PrimesByEratosthenes hurui = new PrimesByEratosthenes(10000);
        int n = sc.NextInt();
        int k = sc.NextInt();

        for (int i = 0; i < hurui.Primes.Length; i++)
        {
            if (n % hurui.Primes[i] == 0)
            {
                Console.WriteLine(n / hurui.Primes[i]);
                return;
            }
        }
        Console.WriteLine(1);

#if DEBUG
        Console.WriteLine("local check"); // Visual Studioのローカル変数チェック用 MainにいくとSolve内のローカル変数消えちゃう
#endif 
    }

 }
/// <summary>
/// クラスを生成した時点でlognの計算時間がかかるので注意
/// </summary>
public class PrimesByEratosthenes
{
    /// <summary>
    /// 素数のリスト
    /// </summary>
    public int[] Primes { get; private set; }
    /// <summary>
    /// 判定を行った最大値
    /// </summary>
    public int Max { get; private set; }

    public PrimesByEratosthenes(int n)
    {
        SortedSet<int> primesCollector = new SortedSet<int>();
        this.Max = n;
        Queue<int>[] tmp = new Queue<int>[2];
        tmp[0] = new Queue<int>();
        tmp[1] = new Queue<int>();
        primesCollector = new SortedSet<int>();
        primesCollector.Add(2);
        int newestPushed = 0;
        for (int i = 3; i < n; i += 2)
        {
            tmp[0].Enqueue(i);
        }
        for (int i = 0; i < Math.Floor(Math.Sqrt(n))+2; i++)
        {
            tmp[(i + 1) % 2].Clear();
            int t = tmp[(i % 2)].Dequeue();
            primesCollector.Add(t); 
            foreach (var item in tmp[i%2])
            {
                if ( item % t != 0)
                {
                    tmp[(i + 1) % 2].Enqueue(item);
                }
            }
            newestPushed = (i + 1) % 2;
        }
        while (tmp[newestPushed].Count != 0)
        {
            primesCollector.Add(tmp[newestPushed].Dequeue());
        }
        Primes = primesCollector.ToArray();
    }
}

public static class Scanner
{
    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }

    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return int.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return double.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            string readData = char.ConvertFromUtf32(Console.Read());
            if (readData == " " || readData == "\n")
                break;
            tmp += readData;
        }
        return long.Parse(tmp);
    }
    public static double[] NextDoubleArray()
    {

        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}
0