bnghtz

sum_n_ad_100__modulus_125.pl

Sep 7th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.21 KB | None | 0 0
  1. #! /usr/bin/perl
  2. use warnings;
  3.  
  4. ################################################################
  5. #  S = (n+1)^100 + (n+2)^100 + (n+3)^100 + ... + (n+k)^100
  6. #  S mod 125 ? 0 ; n,k egész 1 < k < 156
  7. ################################################################
  8. my $StopFirstFind = 1;
  9.  
  10. my ($from, $to) = (2, 155); # mettol meddig menjen k
  11. my ($x, $sum);
  12. my ($min, $max);
  13.  
  14. ALL: foreach my $shift (($from - 1) .. ($to - $from)) {
  15.   my @array = ();
  16.  
  17.   foreach my $n ($from .. $to) {
  18.     my $m = $n + $shift;
  19.     last if $m > $to;
  20.    
  21.     if (@array) {
  22.       $max = $m if $m > $max;
  23.       $min = $m if $m < $min;
  24.     } else {
  25.       $min = $max = $m;
  26.     }
  27.  
  28.     # 1 # % 1000 is enough 'cause of %125
  29.     # 2 # perl punctionality is within 16-17 numbers
  30.     #   # 1000 ** 5 == e15, so it must be right
  31.     $x = (($m ** 5 % 1000) ** 5 % 1000) ** 4 % 1000;
  32.     push(@array, $x);
  33.     $sum = 0;
  34.     map {$sum += ($_ % 1000); } @array;
  35.     printf("%3d,%3d  %5d %3d %3d\n", $min, $max, $sum ,$sum % 1000, $sum % 125);
  36.     if (0 == $sum % 125) {
  37.       print "Haha! i got you!\n\n";
  38.       unless (($min % 5 == 0) && ($max == $min)) {
  39.         sleep(4);
  40.         last ALL if $StopFirstFind;
  41.       }
  42.     }
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment