Jump to content

Magic constant: Difference between revisions

Magic constant en Python
(Added Quackery)
(Magic constant en Python)
Line 488:
</pre>
 
=={{header|Quackery}}==
 
=={{header|Python}}==
<lang python>#!/usr/bin/python
 
def a(n):
n += 2
return n*(n**2 + 1)/2
def inv_a(x):
k = 0
while k*(k**2+1)/2+2 < x:
k+=1
return k
 
if __name__ == '__main__':
print("The first 20 magic constants are:");
for n in range(1, 20):
print(int(a(n)), end = " ");
print("\nThe 1,000th magic constant is:",int(a(1000)));
for e in range(1, 20):
print(f'10^{e}: {inv_a(10**e)}');</lang>
{{out}}
<pre>The first 20 magic constants are:
15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 4641
The 1,000th magic constant is: 503006505.0
10^1: 3
10^2: 6
10^3: 13
10^4: 28
10^5: 59
10^6: 126
10^7: 272
10^8: 585
10^9: 1260
10^10: 2715
10^11: 5849
10^12: 12600
10^13: 27145
10^14: 58481
10^15: 125993
10^16: 271442
10^17: 584804
10^18: 1259922
10^19: 2714418</pre>
 
 
=={{header|Quackery}}==
<lang Quackery> [ 3 + dup 3 ** + 2 / ] is magicconstant ( n --> n )
2,122

edits

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