JavaScript 190
function n(n)
{z=i(n)?n:0
for(x=y=n;!z;x--,y++)z=i(x)?x:i(y)?y:0
for(a=b=1;b<n;c=a+b,a=b,b=c);
return(n+n*n+(2*n-a-b<0?a:b)+z)/4}
function i(n)
{for(j=2;j<n;j++)
if(!(n%j))return 0
return 1}
[257]
function n(n)
{return(n+n*n+p(n)+f(n))/4}
function p(n)
{if(i(n))return n
for(a=b=n;;a--,b++){if(i(a))return a
if(i(b))return b}}
function i(n)
{for(j=2;j<n;j++)
if(!(n%j))return 0
return 1}
function f(n)
{for(a=b=1;b<n;c=a+b,a=b,b=c);
return 2*n-a-b<0?a:b}
未压缩:
function closest( a, b, c )
{
return 2*a-b-c < 0 ? b : c;
}
function closestPrime( n )
{
a=b=n;
if (isPrime( n ) ) return n;
while ( true )
{
a-=1;
b+=1;
if (isPrime(a))return a;
if (isPrime(b))return b;
}
}
function isPrime( n )
{
for (i=2;i<n;i++)
{
if ( !( n % i ) ) return false;
}
return true;
}
function closestFib( n )
{
for(fib1=0,fib2=1;fib2<n;fib3=fib1+fib2,fib1=fib2,fib2=fib3);
return closest( n, fib1, fib2 );
}
function navg(n)
{
n2 = n*n;
np = closestPrime( n );
nf = closestFib( n );
return ( n + n2 + np + nf ) / 4;
}