Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # # # # # # # # # # # #
- # # # # # # # bullshit
- for ($i = 0; $i < 80; $i++)
- {
- print "\n";
- }
- print "mersenne tester\n";
- print "\n";
- print "\n";
- print "format: 2^p-1\n";
- print "if 2^p-1 is prime, it is a mersenne prime\n";
- # # # # # # # # # # # # # #
- # # # # # # get information
- $p = 0;
- $number = 0;
- $half = 0;
- $count = 0;
- $divisor = 0;
- $count_two = 0;
- $divisor = 2;
- # # # # # # # # # # # # #
- # # # # # # begin testing
- print "enter p:\n";
- $p = <STDIN>;
- $number = (2 ** $p) -1;
- print "you entered ", $p, " 2^p is ", ($number + 1), " and number \= $number\n";
- $half = $number / 2;
- print "testing\n";
- $count_two = 1;
- for ($count=1; $count<$half; ++$count)
- {
- ++$count_two;
- if($number % $divisor == 0)
- {
- print "2^", $p, "-1 is not a mersenne prime.\n"; # # # # # # # # # # # #
- print "it took $count_two passes to complete,\n"; # # # # # # # # too bad
- print "and was divided by ", $divisor, ".\n";
- exit(0);
- }
- else
- {
- if($number % $divisor > 0)
- {
- ++$divisor;
- }
- }
- }
- # # # # # # # # # # # #
- # # # # # # # # success
- print "\n";
- print "2^", $p, "-1 is a mersenne prime.\n";
- print "it took $count_two passes to complete.\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement