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 } } /// /// クラスを生成した時点でlognの計算時間がかかるので注意 /// public class PrimesByEratosthenes { /// /// 素数のリスト /// public int[] Primes { get; private set; } /// /// 判定を行った最大値 /// public int Max { get; private set; } public PrimesByEratosthenes(int n) { SortedSet primesCollector = new SortedSet(); this.Max = n; Queue[] tmp = new Queue[2]; tmp[0] = new Queue(); tmp[1] = new Queue(); primesCollector = new SortedSet(); 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; } }