forked from trizen/perl-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaussian_integers_sum.pl
executable file
·77 lines (65 loc) · 3.6 KB
/
gaussian_integers_sum.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
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
# Calculate the terms of the sequences A281964 (real part) and A282132 (imaginary part), using
# Math::AnyNum and Math::GComplex, but without doing any floating-point arithmetic operations.
# See also:
# https://oeis.org/A281964
# https://oeis.org/A282132
# https://en.wikipedia.org/wiki/Gaussian_integer
use 5.020;
use strict;
use warnings;
use experimental qw(signatures);
use Math::GComplex qw(cplx);
use Math::AnyNum qw(:overload factorial);
sub A281964_A282132 ($n) {
my @i = (1, cplx(0, 1), -1, cplx(0, -1));
my $sum = cplx(0, 0);
foreach my $k (1 .. $n) {
$sum += $i[($k - 1) % 4] / $k;
}
return $sum * factorial($n);
}
foreach my $n (1 .. 40) {
printf("%50s %s\n", A281964_A282132($n)->reals);
}
__END__
1 0
2 1
4 3
16 6
104 30
624 300
3648 2100
29184 11760
302976 105840
3029760 1421280
29698560 15634080
356382720 147692160
5111976960 1919998080
71567677440 33106993920
986336870400 496604908800
15781389926400 6638004172800
289206418636800 112846070937600
5205715535462400 2386916704972800
92506221468057600 45351417394483200
1850124429361152000 785383247480832000
41285515024760832000 16493048197097472000
908281330544738304000 413938002507853824000
19766469874751373312000 9520574057680637952000
474395276994032959488000 202641760645450334208000
12480330326584063426560000 5066044016136258355200000
324488588491185649090560000 147228354462873703219200000
8357900428135406889861120000 3975165570497589986918400000
234021211987791392916111360000 100415766523514167472947200000
7091503492257664255068733440000 2912057229181910856715468800000
212745104767729927652062003200000 96203478869197027656007680000000
6329845387987436698577613619200000 2982307844945107857336238080000000
202555052415597974354483635814400000 87211012384065528617034055680000000
6947447566648426683865177994035200000 2877963408674162444362123837440000000
236213217266046507251416051797196800000 106534073513733409603830404874240000000
7972229805272023612951943203258368000000 3728692572980669336134064170598400000000
287000272989792850066269955317301248000000 123899784660917951171159658804019200000000
10991003427412236669919987794890981376000000 4584292032453964193332907375748710400000000
417658130241664993456959536205857292288000000 187966850324476984392966459860031897600000000
15765644461958333633061414687928360108032000000 7330707162654602391325691934541244006400000000
630625778478333345322456587517134404321280000000 272830404424986652294387395641746862899200000000