Find the nearest biquadratic number A biquadratic number is a number that is the fourth power of another integer, for example: 3^4 = 3*3*3*3 = 81

Given an integer as input, output the closest biquadratic number.

Here are the first 15 double-squares:

1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000, 14641, 20736, 28561, 38416, 50625


This is code-golf so fewest bytes in each language wins

This is OEIS A000583
Python 3, 35 bytes



lambda n:int((n**.5-.75)**.5+.5)**4


Try it online!

How it works

The value n at which the output switches from (k − 1)4 to k4 satisfies √(√n − 3/4) + 1/2 = k, or n = ((k − 1/2)2 + 3/4)2 = (k2 − k + 1)2 = ((k − 1)4 + k4 + 1)/2, which is exactly the first integer that’s closer to k4.

(Works for all n ≤ 4504699340341245 = (81924 + 81934 − 7)/2 > 252, after which floating-point roundoff starts to break it, even though it works mathematically for all n.)