View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
David Hilberg David Hilberg is offline
external usenet poster
 
Posts: 84
Default Eulier Totient Function

Dana,

OT and for fun: Do you know how to collect the prime factors geometrically?

This is the Squarest Rectangle Method:

Take Int(Sqrt(n)) as the side length of the largest square of area <= n.
If the square's area = n exactly, each side is a divisor of n.
But if area < n, take the difference and consider it as bricks laid on
top of the square (left to right) forming one or more extra rows and/or
a partial row.
If the top row is complete, this is the squarest rectangle of area n,
and both sides are divisors.
But if the top row is incomplete, remove the rightmost column of bricks,
distribute on top as before, and if it's not a solid rectangle, keep
removing the remaining columns from the right until the top row is
complete. Then each side is a divisor of n.
Eventually, you always end up with a solid rectangle, which gives you
two divisors to break down further by the same method, or else a single
column of bricks whose height must be prime (by exhaustion), which gives
you a prime factor.
In this way, you can collect all prime divisors of n.

- David

Dana DeLouis wrote:
Hi David. I could not find any identities where we could cut down the
number of loops.


Oh! Never mind!! :(
Just call a Prime Factor routine, keeping just the prime numbers.
For example, if n=2,000,000, then just collect 2 & 5.

n = 2,000,000;
Hence:

n*(1 - 1/2)*(1 - 1/5)
800,000

Which checks:

EulerPhi(n)
800,000