How to resolve the algorithm Achilles numbers step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Achilles numbers step by step in the J programming language

Table of Contents

Problem Statement

An Achilles number is a number that is powerful but imperfect. Named after Achilles, a hero of the Trojan war, who was also powerful but imperfect.

A positive integer n is a powerful number if, for every prime factor p of n, p2 is also a divisor. In other words, every prime factor appears at least squared in the factorization. All Achilles numbers are powerful. However, not all powerful numbers are Achilles numbers: only those that cannot be represented as mk, where m and k are positive integers greater than 1.

A strong Achilles number is an Achilles number whose Euler totient (𝜑) is also an Achilles number.

108 is a powerful number. Its prime factorization is 22 × 33, and thus its prime factors are 2 and 3. Both 22 = 4 and 32 = 9 are divisors of 108. However, 108 cannot be represented as mk, where m and k are positive integers greater than 1, so 108 is an Achilles number. 360 is not an Achilles number because it is not powerful. One of its prime factors is 5 but 360 is not divisible by 52 = 25. Finally, 784 is not an Achilles number. It is a powerful number, because not only are 2 and 7 its only prime factors, but also 22 = 4 and 72 = 49 are divisors of it. Nonetheless, it is a perfect power; its square root is an even integer, so it is not an Achilles number.

500 = 22 × 53 is a strong Achilles number as its Euler totient, 𝜑(500), is 200 = 23 × 52 which is also an Achilles number.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Achilles numbers step by step in the J programming language

Source code in the j programming language

achilles=: (*/ .>&1 * 1 = +./)@(1{__&q:)"0
strong=: achilles@(5&p:)


   5 10$(#~ achilles) 1+i.10000  NB. first 50 achilles numbers
  72  108  200  288  392  432  500  648  675  800
 864  968  972 1125 1152 1323 1352 1372 1568 1800
1944 2000 2312 2592 2700 2888 3087 3200 3267 3456
3528 3872 3888 4000 4232 4500 4563 4608 5000 5292
5324 5400 5408 5488 6075 6125 6272 6728 6912 7200
   
   20{.(#~ strong * achilles) 1+i.100000 NB. first twenty strong achilles numbers
500 864 1944 2000 2592 3456 5000 10125 10368 12348 12500 16875 19652 19773 30375 31104 32000 33275 37044 40500
   
   +/achilles (+i.)/1 9*10^<:2  NB. count of two digit achilles numbers
1
   +/achilles (+i.)/1 9*10^<:3
12
   +/achilles (+i.)/1 9*10^<:4
47
   +/achilles (+i.)/1 9*10^<:5
192
   +/achilles (+i.)/1 9*10^<:6
664


  

You may also check:How to resolve the algorithm Sort an integer array step by step in the Maxima programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the PHP programming language
You may also check:How to resolve the algorithm Arithmetic numbers step by step in the Go programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Erlang programming language
You may also check:How to resolve the algorithm Abstract type step by step in the Wren programming language