Exemplo n.º 1
0
    public static void Main()
    {
        SieveOfEratosthenes sieve = new SieveOfEratosthenes(100000);

        sieve.Run();
        int[] q = new int[100010];
        for (int i = 1; i <= 100000; i++)
        {
            if (sieve.IsPrime(i) && sieve.IsPrime((i + 1) / 2))
            {
                q[i] = q[i - 1] + 1;
            }
            else
            {
                q[i] = q[i - 1];
            }
        }
        int Q = NextInt();

        for (int i = 0; i < Q; i++)
        {
            int a = NextInt() - 1, b = NextInt();
            Console.WriteLine(q[b] - q[a]);
        }
    }
Exemplo n.º 2
0
    public static void Main()
    {
        int N = Cin <int>();
        SieveOfEratosthenes soe = new SieveOfEratosthenes(1000010);

        soe.Run();
        Console.WriteLine(soe.IsPrime(N) ? "YES" : "NO");
    }
Exemplo n.º 3
0
 public static bool IsPrime(this int value)
 {
     return(SieveOfEratosthenes.IsPrime(value));
 }