Frobenius numbers: Difference between revisions
Content added Content deleted
(Added AppleScript.) |
(Added XPL0 example.) |
||
Line 1,157: | Line 1,157: | ||
25 such numbers found. |
25 such numbers found. |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number |
|||
int N, I; |
|||
[if N <= 1 then return false; |
|||
for I:= 2 to sqrt(N) do |
|||
if rem(N/I) = 0 then return false; |
|||
return true; |
|||
]; |
|||
int Count, M, Pn, Pn1, F; |
|||
[Count:= 0; |
|||
M:= 2; \first prime |
|||
Pn:= M; |
|||
loop [repeat M:= M+1 until IsPrime(M); |
|||
Pn1:= M; |
|||
F:= Pn*Pn1 - Pn - Pn1; |
|||
if F >= 10_000 then quit; |
|||
IntOut(0, F); |
|||
Count:= Count+1; |
|||
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\); |
|||
Pn:= Pn1; |
|||
]; |
|||
CrLf(0); |
|||
IntOut(0, Count); |
|||
Text(0, " Frobenius numbers found below 10,000. |
|||
"); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 7 23 59 119 191 287 395 615 839 |
|||
1079 1439 1679 1931 2391 3015 3479 3959 4619 5039 |
|||
5615 6395 7215 8447 9599 |
|||
25 Frobenius numbers found below 10,000. |
|||
</pre> |
</pre> |