1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <cstdlib>
#include <cmath>
// Mersene Prime Calculator
using namespace std;
int main ()
{
int input,counter;
cout<<"Enter a Mersenne Number to see it's prime\n"<<endl;
cin>>input;
unsigned long long int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=1;
for(counter=0;counter<input;counter++)//What this does: 2^input
{
a*=2;
b*=2;
c*=2;
d*=2;
e*=2;
f*=2;
g*=2;
h*=2;
i*=2;
j*=2;
k*=2;
l*=2;
if(l>=pow(10,18))
{k=k+(floor (l/pow(10,18)));l=l-((floor (l/pow(10,18)))*pow(10,18));}
if(k>=pow(10,18))
{j=j+(floor (k/pow(10,18)));k=k-((floor (k/pow(10,18)))*pow(10,18));}
if(j>=pow(10,18))
{i=i+(floor (j/pow(10,18)));j=j-((floor (j/pow(10,18)))*pow(10,18));}
if(i>=pow(10,18))
{h=h+(floor (i/pow(10,18)));i=i-((floor (i/pow(10,18)))*pow(10,18));}
if(h>=pow(10,18))
{g=g+(floor (h/pow(10,18)));h=h-((floor (h/pow(10,18)))*pow(10,18));}
if(g>=pow(10,18))
{f=f+(floor (g/pow(10,18)));g=g-((floor (g/pow(10,18)))*pow(10,18));}
if(f>=pow(10,18))
{e=e+(floor (f/pow(10,18)));f=f-((floor (f/pow(10,18)))*pow(10,18));}
if(e>=pow(10,18))
{d=d+(floor (e/pow(10,18)));e=e-((floor (e/pow(10,18)))*pow(10,18));}
if(d>=pow(10,18))
{c=c+(floor (d/pow(10,18)));d=d-((floor (d/pow(10,18)))*pow(10,18));}
if(c>=pow(10,18))
{b=b+(floor (c/pow(10,18)));c=c-((floor (c/pow(10,18)))*pow(10,18));}
if(b>=pow(10,18))
{a=a+(floor (b/pow(10,18)));b=b-((floor (b/pow(10,18)))*pow(10,18));}
}
cout<<"Prime:"<<endl<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<k<<l-1<<endl;
return 0;
}
/*
Enter a Mersenne Number to see it's prime
607
Prime:
05311379928167668776963527775300432691230828002112280985667021944881886003261444
97287621509123871739707887452168914081851469987842907556477576151047502783979430
87104835393219031728127
--------------------------------
Process exited with return value 0
Press any key to continue . . .
*/
|