dimanche 26 novembre 2017

Find prime number bigger than 1 Billion

This code successfully finds the prime number but unfortunately, it can't store a number bigger than 1 Billion in 'int' or 'long'.If I use double than I can't use modulus operator.And if I use 'long long', then I get the "Floating Point Exception" error.So, I don't know which variable type I am supposed to use to store that big number.

int findingPrimeNum()
 {

    int P = 999999999999;

    int count;

    do
     {
       count=0;
       P++;
       for(int a=1;a<=P;a++)
        {
         if(P%a==0)
           {
              count++;  
           }

         }


       }while(count!=2);
   cout<<P<<" is the prime number which is bigger than 10^11"<<endl;

 return P;

 }

Aucun commentaire:

Enregistrer un commentaire