-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.pl
67 lines (51 loc) · 1.66 KB
/
prog.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
# Decimal expansion of the sum of reciprocals of Brazilian primes, also called the Brazilian primes constant.
# https://oeis.org/A306759
use 5.014;
#~ use Math::AnyNum qw(:overload float);
#~ my $sum = float(0);
use Math::MPFR;
my $sum = Math::MPFR::Rmpfr_init2(92);
Math::MPFR::Rmpfr_set_ui($sum, 0, 0);
open my $fh, '<', 't5.txt';
my $str = do {
local $/;
<$fh>;
};
#my $data = eval( do {
# local $/;
# <$fh>;
#} );
close $fh;
my $t = Math::MPFR::Rmpfr_init2(92);
while ($str =~ /(\d+)/g) {
#$sum += Math::AnyNum->new($1)->inv;
Math::MPFR::Rmpfr_set_ui($t, $1, 0);
Math::MPFR::Rmpfr_ui_div($t, 1, $t, 0);
Math::MPFR::Rmpfr_add($sum, $sum, $t, 0);
#~ Math::MPFR::Rmpfr_add_d($sum, $sum, 1/$1, 0);
}
say $sum;
# B(10^19) ~ 0.33175446666446018177571079766533
# 10^12 = 0.331754390677227426801521850173028607337819345774
# 10^14 = 0.331754460113696752705452670945987494053288903943
# 10^15 = 0.331754464735448520879667677495078712564872109224
# 10^16 = 0.331754466101486907998310205443082093679034303966
# 10^17 = 0.33175446650734519516960638465
#~ 0.33175446473544852087966761101
#~ 0.33175446473544851633795978262e-1
#~ 0.331754464735448520879667677495078712564872109224
#~ 0.331754464735448516337959901210319518853745198367
#~ 0.33175446473544851633795984906e-1
#~
# Sum of reciprocals of Brazilian primes <~ 10^k, for k=14: 0.33175446011..., k=15: 0.33175446473..., k=16: 0.331754466101..., and k=17: 0.331754466507... (using Maximilian's PARI program from A085104).
__END__
while (<>) {
/^#/ and next;
my ($n, $p) = split(' ');
$p || next;
$p = Math::AnyNum->new($p);
$sum += 1/$p;
say $sum;
}
say $sum;