-
Notifications
You must be signed in to change notification settings - Fork 0
/
u.pl
40 lines (30 loc) · 813 Bytes
/
u.pl
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
#!/usr/bin/perl
# a(n) is the least integer k such that the remainder of k modulo p is strictly increasing over the first n primes.
# https://oeis.org/A306582
use 5.014;
use ntheory qw(:all);
# 0, 2, 4, 34, 52, 194, 502, 1138, 4042, 5794, 5794, 62488, 798298, 5314448, 41592688
sub foo {
my ($n, $from) = @_;
my $p = nth_prime($n);
my @primes = reverse @{primes(nth_prime($n-1))};
OUTER: for(my $k = $from; ; ++$k) {
my $max = $k%$p;
#my $ok = 1;
foreach my $q(@primes){
if ($k % $q < $max) {
$max = $k%$q;
}
else {
next OUTER;
}
}
return $k;
}
}
my $prev = 5037219688;
foreach my $n(18..100) {
my $t = foo($n, $prev);
say "a($n) = $t";
$prev = $t;
}