using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input4"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("1 10"); //3 //6 //9 } else if (InputPattern == "Input2") { WillReturn.Add("10 20"); //12 //13 //15 //18 } else if (InputPattern == "Input3") { WillReturn.Add("30 40"); //30 //31 //32 //33 //34 //35 //36 //37 //38 //39 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray(); int A = wkArr[0]; int B = wkArr[1]; Predicate Has3 = pInt => { int CopiedVal = pInt; while (CopiedVal > 0) { if (CopiedVal % 10 == 3) return true; CopiedVal /= 10; } return false; }; for (int I = A; I <= B; I++) { if (I % 3 == 0 || Has3(I)) Console.WriteLine(I); } } }