4 ms·
There are lots of ways to approach this topic, but here's my favorite, because it doesn't rely on definitions, just arithmetic... Javascript: function q(n,k){
by i_c_b 13y ago
There are lots of ways to approach this topic, but here's my favorite, because it doesn't rely on definitions, just arithmetic...
Javascript:
function q(n,k){ var t = 0; for( var j = 2; j <= n; j++ )t += 1/k - q(Math.floor(n/j),k+1); return t; }
function p(n){ return q(n,1) - q(n-1,1);}
If you check out values of p(n) for n = 1...16, you'll see you get 0,1,1,.5,1,0,1,.3333333,.5,0,1,0,1,0,0,.25
So notice what p returns here - if n is prime, p(n) is 1. If n is a prime power p^a, its 1/a (hence 16 = 2^4 -> 1/4).
And if n is 1? Then p(n) is 0.
In fact, q(n,1) is a tidy (but slow to compute) expression of the Riemann Prime Counting Function: http://mathworld.wolfram.com/RiemannPrimeCountingFunction.html http://mathworld.wolfram.com/RiemannPrimeCountingFunction.ht....
This doesn't prove anything about the "definition of prime numbers", of course - definitions are social things. But 1 does behave differently from the primes in this function that seems to do nothing at all but explicitly identify primes.
Nothing rigorous here, of course, but I think it's a fun, quick-to-code-and-play-with example.