Wolstenholme numbers: Difference between revisions
Content deleted Content added
Added C |
Wolstenholme numbers in FreeBASIC |
||
Line 105:
Same as Wren example.
</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">#include "isprime.bas"
Function GCD(n As Uinteger, d As Uinteger) As Uinteger
Return Iif(d = 0, n, GCD(d, n Mod d))
End Function
Function numArmonico(n As Uinteger, m As Uinteger) As Uinteger
Dim As Integer i, v = 0, f = 1
For i = 1 To n
f *= i ^ m
Next i
For i = 1 To n
v += f / i ^ m
Next i
v /= GCD(v, f)
Return v
End Function
Dim As Integer i, wols(12)
Print "First 12 Wolstenholme numbers:"
For i = 1 To 12
wols(i) = numArmonico (i,2)
Print wols(i)
Next i
Print !"\nTwo Wolstenholme primes:"
For i = 1 To 12
If isPrime(wols(i)) Then Print wols(i)
Next i
Sleep</syntaxhighlight>
{{out}}
<pre>First 12 Wolstenholme numbers:
1
5
49
205
5269
5369
266681
1077749
9778141
1968329
239437889
240505109
Two Wolstenholme primes:
5
266681</pre>
=={{header|J}}==
|