-
Notifications
You must be signed in to change notification settings - Fork 0
/
formula.sf
50 lines (39 loc) · 2 KB
/
formula.sf
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
#!/usr/bin/ruby
func f(n) {
var terms = []
terms << n.lpf
while (n.is_semiprime && n.is_squarefree) {
var f = n.factor
n = (f[1] - f[0])
terms << f[0]
}
var p = terms.pop
var q = n
var t = "#{q}"
while (terms) {
t = "#{p}*(#{p} + #{t})"
p = terms.pop
}
return t
}
#6, 34, 82, 226, 687, 4786, 14367, 28738, 373763, 21408927, 158279834
#~ say f(373763)
#~ say f(21408927)
#~ say f(158279834)
for k in (6, 34, 82, 226, 687, 4786, 14367, 28738, 373763, 21408927, 158279834, 2690757467, 36906080234) {
say "#{k} = #{f(k)}"
assert_eq(k, eval(f(k)))
}
__END__
6 = 2*(2 + 1)
34 = 2*(2 + 3*(3 + 2))
82 = 2*(2 + 3*(3 + 2*(2 + 3)))
226 = 2*( 2 + 3*(3 + 2*(2 + 3*(3 + 2))))
687 = 3*(3 + 2*( 2 + 3*(3 + 2*(2 + 3*(3 + 2)))))
4786 = 2*(2 + 3*(3 + 2*( 2 + 5*(5 + 2*(2 + 5*(5 + 2))))))
14367 = 3*(3 + 2*(2 + 3*(3 + 2*( 2 + 5*(5 + 2*(2 + 5*(5 + 2)))))))
28738 = 2*( 2 + 3*(3 + 2*(2 + 3*(3 + 2*( 2 + 5*(5 + 2*(2 + 5*(5 + 2))))))))
373763 = 13*(13 + 2*( 2 + 3*(3 + 2*(2 + 3*(3 + 2*( 2 + 5*(5 + 2*(2 + 5*(5 + 2)))))))))
21408927 = 3*(3 + 2*( 2 + 23*( 23 + 2*(2 + 5*(5 + 2*(2 + 23*(23 + 2*(2 + 5*(5 + 2*(2 + 11))))))))))
158279834 = 2*(2 + 5*(5 + 2*( 2 + 461*(461 + 2*(2 + 7*(7 + 2*(2 + 3*( 3 + 2*(2 + 5*(5 + 2*(2 + 5)))))))))))
2690757467 = 17*(17 + 2*(2 + 5*(5 + 2*( 2 + 461*(461 + 2*(2 + 7*(7 + 2*(2 + 3*( 3 + 2*(2 + 5*(5 + 2*(2 + 5))))))))))))