Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

replace equation bitmap images with MathJax
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition $$\small{a(p)-a(p-1)=1}\text{ for all primes }p\text{ and }a(km)=a(k)+a(m)\text{ for all }k,m\in \mathbb{N}$$

By Euler's product formula

Euler's product formula $$\small{\varphi(n)=n\prod_{p|n}\left(1-{1\over p}\right)=n\prod_{p|n}{{p-1}\over p}}$$

where φ\$\varphi\$ denotes Euler's totient function and p\$p\$ varies only over prime numbers.

Combining both, we deduce the property

first property $$\small{a(\varphi(n))=a\left(n\prod_{p|n}{{p-1}\over p}\right)=a(n)+\sum_{p|n}\left(a(p-1)-a(p)\right)=a(n)-\sum_{p|n}{1=a(n)-\omega(n)}}$$

where ω\$\omega\$ denotes the number of distinct prime factors of n\$n\$.

Applying the resulting formula k + 1\$k + 1\$ times, where k\$k\$ is large enough so that φk+1(n) = 1\$\varphi^{k+1}(n)=1\$, we get

second property $$\small{ \begin{aligned} 0=a\left(\varphi^{k+1}(n)\right)=a\left(\varphi^k(n)\right)-\omega\left(\varphi^k(n)\right)&=a\left(\varphi^{k-1}(n)\right)-\omega\left(\varphi^{k-1}(n)\right)-\omega\left(\varphi^k(n)\right) \\ &= \cdots = a(n)-\sum_{j=0}^k\omega\left(\varphi^j(n)\right) \end{aligned} }$$

From this property, we obtain the formula

formula $$\small{a(n)=\sum_{j=0}^k\omega\left(\varphi^j(n)\right)=\sum_{j=0}^{+\infty}\omega\left(\varphi^j(n)\right)}$$

where the last equality holds because ω(1) = 0\$\omega(1)=0\$.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the resulting formula k + 1 times, where k is large enough so that φk+1(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

$$\small{a(p)-a(p-1)=1}\text{ for all primes }p\text{ and }a(km)=a(k)+a(m)\text{ for all }k,m\in \mathbb{N}$$

By Euler's product formula

$$\small{\varphi(n)=n\prod_{p|n}\left(1-{1\over p}\right)=n\prod_{p|n}{{p-1}\over p}}$$

where \$\varphi\$ denotes Euler's totient function and \$p\$ varies only over prime numbers.

Combining both, we deduce the property

$$\small{a(\varphi(n))=a\left(n\prod_{p|n}{{p-1}\over p}\right)=a(n)+\sum_{p|n}\left(a(p-1)-a(p)\right)=a(n)-\sum_{p|n}{1=a(n)-\omega(n)}}$$

where \$\omega\$ denotes the number of distinct prime factors of \$n\$.

Applying the resulting formula \$k + 1\$ times, where \$k\$ is large enough so that \$\varphi^{k+1}(n)=1\$, we get

$$\small{ \begin{aligned} 0=a\left(\varphi^{k+1}(n)\right)=a\left(\varphi^k(n)\right)-\omega\left(\varphi^k(n)\right)&=a\left(\varphi^{k-1}(n)\right)-\omega\left(\varphi^{k-1}(n)\right)-\omega\left(\varphi^k(n)\right) \\ &= \cdots = a(n)-\sum_{j=0}^k\omega\left(\varphi^j(n)\right) \end{aligned} }$$

From this property, we obtain the formula

$$\small{a(n)=\sum_{j=0}^k\omega\left(\varphi^j(n)\right)=\sum_{j=0}^{+\infty}\omega\left(\varphi^j(n)\right)}$$

where the last equality holds because \$\omega(1)=0\$.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.
Commonmark migration
Source Link

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the resulting formula k + 1 times, where k is large enough so that φk+1(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the resulting formula k + 1 times, where k is large enough so that φk+1(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the resulting formula k + 1 times, where k is large enough so that φk+1(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.
deleted 9 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the resulting formula k + 1 times, where k is large enough so that φk+1(n) = φk(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the formula k times, where k is large enough so that φk+1(n) = φk(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.

Jelly, 9 bytes

ÆṪÐL·ÆFL€S

Try it online! or verify all test cases.

Background

The definition of sequence A064097 implies that

definition

By Euler's product formula

Euler's product formula

where φ denotes Euler's totient function and p varies only over prime numbers.

Combining both, we deduce the property

first property

where ω denotes the number of distinct prime factors of n.

Applying the resulting formula k + 1 times, where k is large enough so that φk+1(n) = 1, we get

second property

From this property, we obtain the formula

formula

where the last equality holds because ω(1) = 0.

How it works

ÆṪÐL·ÆFL€S Main link. Argument: n
 ÐL· Repeatedly apply the link to the left until the results are no longer
 unique, and return the list of unique results.
ÆṪ Apply Euler's totient function.
 Since φ(1) = 1, This computes φ-towers until 1 is reached.
 ÆF Break each resulting integer into [prime, exponent] pairs.
 L€ Compute the length of each list.
 This counts the number of distinct prime factors.
 S Add the results.
added 25 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
added 10 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
edited body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830
Loading

AltStyle によって変換されたページ (->オリジナル) /