Wolstenholme numbers: Difference between revisions

m
→‎{{header|Python}}: simplify output functions
m (→‎{{header|Python}}: simplify output functions)
Line 35:
""" Wolstenholme numbers """
return sum(Fraction(1, i*i) for i in range(1, k+1)).numerator
 
 
def lineprintbig(bignum, digitstoshow=60, endchar="\n"):
""" Print a large number on one line, show beginning / end and number of digits """
i, wstr = max(digitstoshow // 2, 5), str(bignum)
strlen = len(wstr)
if strlen > digitstoshow:
print(wstr[:i], '...', wstr[-i-1:], f'({strlen} digits)', end=endchar)
else:
print(wstr, end=endchar)
 
 
def process_wolstenholmes(nmax):
Line 52 ⟶ 41:
print('First 20 Wolstenholme numbers:')
for i in wols[:20]:
lineprintbigprint(i)
print('\nFour Wolstenholme primes:')
for j in filter(isprime, wols):
lineprintbigprint(j)
 
 
4,102

edits