[ACM]Q10325: The Lottery
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q10325
{
class Program
{
static private int[] nm, rs; static private char[] par = { ' ' }; static private bool tof; static private int count;
static void Main(string[] args)
{
for (; ; )
{
labelnm: Console.Write("n m>>>");
try
{
nm = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (nm.Length != 2 || nm[1] == 1) throw new Exception();
}
catch { goto labelnm; }
labelrs: Console.Write("Integer>>>");
try
{
rs = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
if (rs.Length != nm[1]) throw new Exception();
}
catch { goto labelrs; }
Array.Sort(rs); count = 1;
for (int i = 2; i <= nm[0]; i++)
{
tof = true;
for (int j = 0; j < rs.Length; j++)
{
if (i % rs[j] == 0) { tof = false; break; }
}
if (tof) count++;
}
Console.WriteLine("Ans={0}", count);
}
}
}
}