Jump to content

Giuga numbers: Difference between revisions

m (→‎alternative version: extreme cheating: limit the used factors in the specific column 3041 is highest factor at column 5)
Line 189:
30 858 1722 66198</lang>
 
These numbers have some interesting properties but there's an issue with guaranteeing correctness of more sophisticated approaches. That said, here's a translation of the pari/gp implementation on the talk page:
 
<lang J>divisors=: [: /:~@, */&>@{@((^ i.@>:)&.>/)@q:~&__
 
giuga=: {{
r=. i.0
p=. (2) 0 1} s=. 1r2,}.(2>.y-1+t=.1)$0
while. t do.
p=. p t}~ 4 p:t{p
s=. s t}~ (s{~t-1)+1%t{p
if. (1=t{s) +. 1 >: (t{s)+(y-t+1)%t{p do.
t=. t-1
elseif. t<y-3 do.
p=. p (t+1)}~ (p{~t) >. (%-.)s{~t
t=. t+1
else.
'c d'=. 2 x: s{~y-3
dc=. d-c
k=. (d^2)-dc
for_h. ({.~ <.@-:@>:@#) f=. divisors k do.
if. 0=dc|h+d do.
if. 0=dc|dkh=. d+k%h do.
py3=. p{~y-3
if. py3 < r1=. (h+d)%dc do.
if. py3 < r2=. dkh%dc do.
if. r1~:r2 do.
if. 1 p: r1 do.
if. 1 p: r2 do.
r=. r, d*r1*r2
end.
end.
end.
end.
end.
end.
end.
end.
end.
end.
r
}}</lang>
 
Example use:<lang J> giuga 1
 
giuga 2
 
giuga 3
30
giuga 4
1722 858
giuga 5
66198
giuga 6
24423128562 2214408306</lang>
 
=={{header|Julia}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.