Want more features on Pastebin? Sign Up, it's FREE!
Guest

mers2.pl

By: a guest on Jan 10th, 2013  |  syntax: Perl  |  size: 1.30 KB  |  views: 70  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl
  2.  
  3. # # # # # # # # # # # #
  4. # # # # # # # bullshit
  5.  
  6.  
  7. for ($i = 0; $i < 80; $i++)
  8.         {
  9.         print "\n";
  10.         }
  11.  
  12.  
  13. print "mersenne tester\n";
  14. print "\n";
  15. print "\n";
  16. print "format: 2^p-1\n";
  17. print "if 2^p-1 is prime, it is a mersenne prime\n";
  18.  
  19. # # # # # # # # # # # # # #
  20. # # # # # # get information
  21.  
  22. $p = 0;
  23. $number = 0;
  24. $half = 0;
  25. $count = 0;
  26. $divisor = 0;
  27.  
  28. $count_two = 0;
  29.  
  30. $divisor = 2;
  31.  
  32.  
  33. # # # # # # # # # # # # #
  34. # # # # # # begin testing
  35.  
  36. print "enter p:\n";
  37. $p = <STDIN>;
  38.  
  39. $number = (2 ** $p) -1;
  40.  
  41. print "you entered ", $p, " 2^p is ", ($number + 1), " and number \= $number\n";
  42.  
  43. $half = $number / 2;
  44.  
  45. print "testing\n";
  46.  
  47. $count_two = 1;
  48.  
  49. print "\n\n";
  50.  
  51. for ($count=1; $count<$half; ++$count)
  52.         {
  53.         ++$count_two;
  54.         if($number % $divisor == 0)
  55.                 {
  56.                 print "2^", $p, "-1 is not a mersenne prime.\n";        # # # # # # # # # # # #
  57.                 print "it took $count_two passes to complete,\n";       # # # # # # # # too bad
  58.                 print "and was divided by ", $divisor, ".\n";
  59.                 exit(0);
  60.                 }
  61.                 else
  62.                 {
  63.                         if($number % $divisor > 0)
  64.                         {
  65.                         ++$divisor;
  66.                        
  67.                         print "pass # $count\n";
  68.                         }
  69.                 }
  70.         }
  71.  
  72. # # # # # # # # # # # #
  73. # # # # # # # # success
  74.  
  75. print "\n";
  76. print "2^", $p, "-1 is a mersenne prime.\n";
  77. print "it took $count_two passes to complete.\n";
  78.  
  79. $char_quit = <STDIN>;
clone this paste RAW Paste Data