Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //a bignum library written in C++, it can (in theory) calculate with 4 billion digit long numbers
- //this is mostly for demonstration purposes, if you need performance, use something like GNU arbitrary precision library
- //Implemented by: http://www.youtube.com/user/thecplusplusguy
- //this might be an older version, I have to check
- //this one find the first 50 mersenne prime (LOL, if you have enough time :)
- #include <iostream>
- #include <fstream>
- #include "bignum.h"
- #include <string>
- bool is_prime(int cur)
- {
- int tmp=3;
- // std::cout << cur << std::endl;
- while(tmp*tmp<cur)
- {
- if((cur%tmp)==0)
- return false;
- tmp+=2;
- }
- return true;
- }
- void nextprime(int& cur)
- {
- if(cur==2)
- {
- cur=3;
- return;
- }
- cur+=2;
- while(!is_prime(cur))
- cur+=2;
- }
- int main()
- {
- bignum bn(1);
- bignum tmp;
- bignum tmp2;
- int i=0;
- int j=3;
- int j2=0;
- int diff;
- int mult;
- while(i<50)
- {
- diff=j-j2;
- mult=1;
- mult<<=diff;
- bn*=mult;
- tmp=bn-1;
- tmp2=4;
- std::cout << 2 << " " << 4 << std::endl; //manually this one
- for(int k=0;k<j-2;k++)
- {
- // std::cout << (tmp2*tmp2) << std::endl;
- tmp2=((tmp2*tmp2)-2)%tmp;
- // std::cout << bn << " " << k << " " << tmp2 << std::endl;
- }
- if(tmp2==0)
- {
- std::cout << j << " " << tmp << std::endl;
- i++;
- }
- j2=j;
- nextprime(j);
- }
- std::cout << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement