結果
| 問題 |
No.136 Yet Another GCD Problem
|
| コンテスト | |
| ユーザー |
syoken_desuka
|
| 提出日時 | 2015-02-27 13:54:23 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 4,217 bytes |
| コンパイル時間 | 1,185 ms |
| コンパイル使用メモリ | 111,220 KB |
| 実行使用メモリ | 28,672 KB |
| 最終ジャッジ日時 | 2024-06-23 22:37:14 |
| 合計ジャッジ時間 | 3,579 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
コンパイルメッセージ
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.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;
}
}
syoken_desuka