Post by Ahk_BR » 22 Jan 2023, 07:15
Hi. Wanna help with this task:
https://rosettacode.org/wiki/Achilles_numbers
1 - Find the first 50 Achilles Numbers
Code: Select all
;returns divisors for 1 .. n
divisores(num)
{
serie := ""
loop % num
if !mod(num,a_index)
serie .= a_index ","
return serie
}
;return quantity of common factors
gcd(serieA,serieB)
{
emComum := 0
loop,parse,serieA,csv
if A_LoopField in %serieB%
emComum += 1
return emComum
}
phi(num)
{
phicount := 0
numA := divisores(num)
loop % num
{
numB := divisores(A_Index)
fim := gcd(numA,numB)
if (fim = 1)
phicount += 1
}
return phicount
}
; returns 0 or 1
isAchilles(n) {
pw := isPowerfull(n)
if !pw
return 0
loop, parse, pw, `n
ttt := A_Index
if (ttt = 2)
return 0
if mod(n,(ceil(sqrt(n))**2)) ; ---------------------------
;if mod(n,(foo**3)) ; HERE IS THE PROBLEM. HOW TO KNOW IF
return 1 ; A NUMBER HAS A INTEGER CUBIC ROOT? EX: 216 and 1000
return 0
}
; returns 0 or 1
isPowerfull(n)
{
ttt := factor(n)
sort,ttt,N U D`n
loop,parse,ttt,`n
if mod(n,A_LoopField**2)
return false
return ttt
}
; NOT USING UNTIL NOW BUT POSSIBLY WILL
; factoring integers from https://rosettacode.org/wiki/Prime_decomposition#AutoHotkey
; return each factor by line Ex: 100 = 2 `n 2 `n 5 `n 5
factor(n)
{
if (n = 1)
return
f = 2
while (f <= n) ;Floor(sqrt(n)))
{
if (Mod(n, f) = 0)
{
next := factor(n / f)
return, % f "`n" next
}
f++
}
}
; NOT USING UNTIL NOW BUT POSSIBLY WILL
; list(0) / count(1) of prime numbers
; ex: msgbox % PrimesLiCo(100,1) - return a list
; MsgBox % PrimesLiCo(100,0) - return a number
PrimesLiCo(max,listar:=0) {
primos := ""
countPrimes := -1
loop %max%
{
numero := A_Index
apoio := maxDivisor := Floor(Sqrt(numero))
loop %maxDivisor%
{
if (apoio=1)
{
if listar
primos := primos . numero ","
else
countPrimes += 1
break
}
if mod(numero,apoio)
apoio -= 1
else
break
}
}
if listar
return primos
else
return countPrimes
}
out := "First 50 Achilles:`n"
loop
{
;if isPowerfull(A_Index)
if isAchilles(A_Index)
{
out .= A_Index ", "
Acount += 1
if (Acount = 50)
break
}
}
MsgBox % out
ExitApp
^q::
ExitApp
/* RESULT
---------------------------
Achilles Numbers 3.ahk
---------------------------
First 50 Achilles:
72, 108, 200, 216, 288, 392, 432, 500, 648, 675, 800, 864, 968, 972, 1000, 1125, 1152, 1323,
1352, 1372, 1568, 1728, 1800, 1944, 2000, 2312, 2592, 2700, 2744, 2888, 3087, 3200, 3267, 3375,
3456, 3528, 3872, 3888, 4000, 4232, 4500, 4563, 4608, 5000, 5292, 5324, 5400, 5408, 5488, 5832,
---------------------------
OK
---------------------------
right answer:
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
non-expected numbers. I dont fully understand to create an algorithm to catch then:
216 = 6 ** 3
1000 = 10 ** 3
1728 =
2744 =
3275 =
5832 =
I tried to pre-generate a inicial list with 2..9 ** 2..11 :
-------
aa := 2
sss := 2
loop 7
{
loop 9
rrr .= (a_index+1) ** aa ","
aa += 1
}
sort,rrr,N U D,
msgbox % rrr
--------
rrr: "4,8,9,16,25,27,32,36,49,64,81,100,125,128,216,243,256,343,512,625,729,1000,1024,1296,2187,2401,3125,4096,6561,7776,10000,15625,16384,16807,32768,46656,59049,65536,78125,100000,117649,262144,279936,390625,531441,823543,1000000,1679616,2097152,4782969,5764801,10000000,16777216,43046721,100000000"
Hi. Wanna help with this task:
https://rosettacode.org/wiki/Achilles_numbers
1 - Find the first 50 Achilles Numbers
[code]
;returns divisors for 1 .. n
divisores(num)
{
serie := ""
loop % num
if !mod(num,a_index)
serie .= a_index ","
return serie
}
;return quantity of common factors
gcd(serieA,serieB)
{
emComum := 0
loop,parse,serieA,csv
if A_LoopField in %serieB%
emComum += 1
return emComum
}
phi(num)
{
phicount := 0
numA := divisores(num)
loop % num
{
numB := divisores(A_Index)
fim := gcd(numA,numB)
if (fim = 1)
phicount += 1
}
return phicount
}
; returns 0 or 1
isAchilles(n) {
pw := isPowerfull(n)
if !pw
return 0
loop, parse, pw, `n
ttt := A_Index
if (ttt = 2)
return 0
if mod(n,(ceil(sqrt(n))**2)) ; ---------------------------
;if mod(n,(foo**3)) ; HERE IS THE PROBLEM. HOW TO KNOW IF
return 1 ; A NUMBER HAS A INTEGER CUBIC ROOT? EX: 216 and 1000
return 0
}
; returns 0 or 1
isPowerfull(n)
{
ttt := factor(n)
sort,ttt,N U D`n
loop,parse,ttt,`n
if mod(n,A_LoopField**2)
return false
return ttt
}
; NOT USING UNTIL NOW BUT POSSIBLY WILL
; factoring integers from https://rosettacode.org/wiki/Prime_decomposition#AutoHotkey
; return each factor by line Ex: 100 = 2 `n 2 `n 5 `n 5
factor(n)
{
if (n = 1)
return
f = 2
while (f <= n) ;Floor(sqrt(n)))
{
if (Mod(n, f) = 0)
{
next := factor(n / f)
return, % f "`n" next
}
f++
}
}
; NOT USING UNTIL NOW BUT POSSIBLY WILL
; list(0) / count(1) of prime numbers
; ex: msgbox % PrimesLiCo(100,1) - return a list
; MsgBox % PrimesLiCo(100,0) - return a number
PrimesLiCo(max,listar:=0) {
primos := ""
countPrimes := -1
loop %max%
{
numero := A_Index
apoio := maxDivisor := Floor(Sqrt(numero))
loop %maxDivisor%
{
if (apoio=1)
{
if listar
primos := primos . numero ","
else
countPrimes += 1
break
}
if mod(numero,apoio)
apoio -= 1
else
break
}
}
if listar
return primos
else
return countPrimes
}
out := "First 50 Achilles:`n"
loop
{
;if isPowerfull(A_Index)
if isAchilles(A_Index)
{
out .= A_Index ", "
Acount += 1
if (Acount = 50)
break
}
}
MsgBox % out
ExitApp
^q::
ExitApp
[/code]
/* RESULT
---------------------------
Achilles Numbers 3.ahk
---------------------------
First 50 Achilles:
72, 108, 200, 216, 288, 392, 432, 500, 648, 675, 800, 864, 968, 972, 1000, 1125, 1152, 1323,
1352, 1372, 1568, 1728, 1800, 1944, 2000, 2312, 2592, 2700, 2744, 2888, 3087, 3200, 3267, 3375,
3456, 3528, 3872, 3888, 4000, 4232, 4500, 4563, 4608, 5000, 5292, 5324, 5400, 5408, 5488, 5832,
---------------------------
OK
---------------------------
right answer:
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
non-expected numbers. I dont fully understand to create an algorithm to catch then:
216 = 6 ** 3
1000 = 10 ** 3
1728 =
2744 =
3275 =
5832 =
I tried to pre-generate a inicial list with 2..9 ** 2..11 :
-------
aa := 2
sss := 2
loop 7
{
loop 9
rrr .= (a_index+1) ** aa ","
aa += 1
}
sort,rrr,N U D,
msgbox % rrr
--------
rrr: "4,8,9,16,25,27,32,36,49,64,81,100,125,128,216,243,256,343,512,625,729,1000,1024,1296,2187,2401,3125,4096,6561,7776,10000,15625,16384,16807,32768,46656,59049,65536,78125,100000,117649,262144,279936,390625,531441,823543,1000000,1679616,2097152,4782969,5764801,10000000,16777216,43046721,100000000"