コード例 #1
0
ファイル: Erato.cs プロジェクト: 0252497/Tableau2
        static void Main(string[] args)
        {
            int entier;

            if (args.Length == 0)
            {
                entier = 100;
            }

            else if (!int.TryParse(args[0], out entier))
            {
                ColorWriteLine(Red, "{0} doit être un nombre entier", args[0]);
                return;
            }

            List <int> nombresEntiers = Crible.Ératosthène(entier);

            ColorWriteLine(Cyan, "Nombres premiers <= {0}\n", entier);

            for (int i = 0; i < nombresEntiers.Count; ++i)
            {
                if (i % 2 == 0)
                {
                    ColorWrite(Yellow, "{0} ", nombresEntiers[i]);
                }
                else
                {
                    ColorWrite(Magenta, "{0} ", nombresEntiers[i]);
                }
            }

            WriteLine("");
        }
コード例 #2
0
 public void _01_Ératosthène()
 {
     AreEqual(new int[0], Crible.Ératosthène(1));
     AreEqual(new int[] { 2 }, Crible.Ératosthène(2));
     AreEqual(new int[] { 2, 3 }, Crible.Ératosthène(4));
     AreEqual(new int[] { 2, 3, 5, 7, 11, 13, 17, 19 }, Crible.Ératosthène(20));
     AreEqual(new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 },
              Crible.Ératosthène());
     Assert.AreEqual(997, Crible.Ératosthène(1000).Last());
     Assert.AreEqual(9973, Crible.Ératosthène(10000).Last());
     Assert.AreEqual(99991, Crible.Ératosthène(100000).Last());
 }