using System; class Program { static void Main(string[] args) { // L と R を入力する //Console.WriteLine("L を入力してください:"); string[] L_R = Console.ReadLine().Split(' '); int L = int.Parse(L_R[0]); //Console.WriteLine("R を入力してください:"); int R = int.Parse(L_R[1]); // 集合 S を作成する int[] S = new int[R - L + 1]; for (int i = 0; i < S.Length; i++) { S[i] = i + L; } // すべての組み合わせに対してコストを計算し、メモリに保存する int[,] costs = new int[R - L + 1, R - L + 1]; for (int i = 0; i < costs.GetLength(0); i++) { for (int j = 0; j < costs.GetLength(1); j++) { costs[i, j] = S[i] % S[j]; } } // 最小コストを求める int minCost = int.MaxValue; for (int i = 0; i < costs.GetLength(0); i++) { for (int j = 0; j < costs.GetLength(1); j++) { // 最小コストを更新する if (costs[i, j] < minCost) { minCost = costs[i, j]; } } } // 結果を出力する //Console.WriteLine("最小コストは {0} です。", minCost); Console.WriteLine(minCost); } }