Gomathi Palaniswamy

Gomathi Palaniswamy

  • NA
  • 3.5k
  • 2.2m

prime no

Dec 7 2010 2:24 AM
Sir/Madam,

    How to find the prime number between 2^511 and 2^512.I have tried the below code but its not giving proper output.
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            bool prime = false;
            Console.WriteLine((Math.Pow(2,511)).ToString());
            Console.WriteLine((Math.Pow(2, 512)).ToString());
            double a = Math.Pow(2, 511);
            double b=Math.Pow(2, 512);
            Console.WriteLine((b-a).ToString());
            while (a < b)
            {
                for (double i = 2; i < 10; i++)
                {
                    if (a % i == 0)
                    {
                        prime = true;
                        //Console.WriteLine(i.ToString());
                        break;
                    }
                }
                if (prime == false)
                {
                   // Console.WriteLine(a.ToString());
                    break;
                }
                a = a + 1;             
               
            }
            Console.ReadLine();
        }
    }
}
Thanks in advance...

Answers (5)