Tuesday 30 October 2018

Hacktoberfest Fifth Pull Request

For my last pull request I again contributed to consumable algorithms library (yes, I like Math and algorithms). This time I chose Euler's Totient Function.
Euler's Totient Function counts the positive integers up to a given integer n that are relatively prime to n (relatively prime numbers are numbers that have only one common divisor - 1).

This is how Euler's function looks like:

The solution of the problem is reduced to one formula:
f(n) = (P1^B1 - P1^(B1 - 1))*(P2^B2 - P2^(B2 - 1)).....*(Pm^Bm - Pm^(Bm - 1)), where P are prime divisors of n and B are powers of divisors.

That's, to find f(n) we need

  • to find prime divisors of n and powers of divisors
  • to write fast power function
  • for fast power function we need to write Bitset class
You can see all code with JSDocs comments here.

No comments:

Post a Comment