-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog.pl
98 lines (78 loc) · 3.35 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl
# Numbers of the form N = a+b+c such that N^3 = concat(a,b,c); a, b, c > 0.
# https://oeis.org/A328198
# Terms of A328198:
# 8, 45, 1611, 4445, 4544, 4949, 5049, 5455, 5554, 7172, 19908, 55556, 60434, 77778, 422577, 427868, 461539, 478115, 488214, 494208, 543752, 559846, 598807, 664741, 757835, 791505, 807598, 4927940, 5555555, 6183170
# Cubes of the form N^3 = concat(a,b,c) with N = a+b+c; a, b, c > 0.
# https://oeis.org/A328200
# Terms of A328200:
# 512, 91125, 4181062131, 87824421125, 93824221184, 121213882349, 128711132649, 162324571375, 171323771464, 368910352448, 7890107061312, 171471879319616, 220721185826504, 470511577514952, 75460133084214033, 78330233506116032, 98316229404133819, 109294197946170875
# Triples (a,b,c) such that (a+b+c)^3 = concat(a,b,c), a, b, c > 0, ordered by size of this value.
# https://oeis.org/A328199
use 5.020;
use strict;
use warnings;
use ntheory qw(:all);
use experimental qw(signatures);
sub isok($n) {
my $N = powint($n, 3);
my @d = todigits($N);
my $e = $#d;
foreach my $i(0..$e) {
my $a = join'',@d[0..$i];
last if ($a > $n);
foreach my $j ($i+1 .. $e) {
next if ($d[$i+1] == 0);
my $b = join'', @d[$i+1..$j];
last if ($b > $n);
foreach my $k($j+1..$e) {
next if ($d[$j+1] == 0);
my $c = join'', @d[$j+1..$e];
last if ($c > $n);
my $s = ($a + $b + $c);
if ($s == $n) {
say "cbrt($N) = $a + $b + $c = $s";
return 1;
}
elsif ($s > $n) {
return 0;
}
}
}
}
return 0;
}
for my $n (1..1e9) {
isok($n);
}
__END__
cbrt(512) = 5 + 1 + 2 = 8
cbrt(91125) = 9 + 11 + 25 = 45
cbrt(4181062131) = 418 + 1062 + 131 = 1611
cbrt(87824421125) = 878 + 2442 + 1125 = 4445
cbrt(93824221184) = 938 + 2422 + 1184 = 4544
cbrt(121213882349) = 1212 + 1388 + 2349 = 4949
cbrt(128711132649) = 1287 + 1113 + 2649 = 5049
cbrt(162324571375) = 1623 + 2457 + 1375 = 5455
cbrt(171323771464) = 1713 + 2377 + 1464 = 5554
cbrt(368910352448) = 3689 + 1035 + 2448 = 7172
cbrt(7890107061312) = 7890 + 10706 + 1312 = 19908
cbrt(171471879319616) = 17147 + 18793 + 19616 = 55556
cbrt(220721185826504) = 22072 + 11858 + 26504 = 60434
cbrt(470511577514952) = 47051 + 15775 + 14952 = 77778
cbrt(75460133084214033) = 75460 + 133084 + 214033 = 422577
cbrt(78330233506116032) = 78330 + 233506 + 116032 = 427868
cbrt(98316229404133819) = 98316 + 229404 + 133819 = 461539
cbrt(109294197946170875) = 109294 + 197946 + 170875 = 478115
cbrt(116367227503144344) = 116367 + 227503 + 144344 = 488214
cbrt(120706126590246912) = 120706 + 126590 + 246912 = 494208
cbrt(160769107975275008) = 160769 + 107975 + 275008 = 543752
cbrt(175471156639227736) = 175471 + 156639 + 227736 = 559846
cbrt(214714120150263943) = 214714 + 120150 + 263943 = 598807
cbrt(293736149984221021) = 293736 + 149984 + 221021 = 664741
cbrt(435235164725157875) = 435235 + 164725 + 157875 = 757835
cbrt(495862183018112625) = 495862 + 183018 + 112625 = 791505
cbrt(526727149679131192) = 526727 + 149679 + 131192 = 807598
cbrt(119673015472102184000) = 1196730 + 1547210 + 2184000 = 4927940
cbrt(171467712620032578875) = 1714677 + 1262003 + 2578875 = 5555555
cbrt(236392428062461013000) = 2363924 + 2806246 + 1013000 = 6183170