Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
46
Task/Smith-numbers/Amazing-Hopper/smith-numbers.hopper
Normal file
46
Task/Smith-numbers/Amazing-Hopper/smith-numbers.hopper
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <basico.h>
|
||||
|
||||
#proto muestranúmeroencontrado(_X_)
|
||||
|
||||
algoritmo
|
||||
|
||||
resultado={}, primos="", suma1=0, suma2=0 , i=1
|
||||
temp_primos=0,
|
||||
|
||||
fijar separador 'NULO'
|
||||
decimales '0'
|
||||
|
||||
iterar para ( num=4, #(num<=10000), ++num )
|
||||
ir por el siguiente si ' es primo(num) '
|
||||
obtener divisores de (num);
|
||||
luego obtener los primos de esto para 'primos'
|
||||
|
||||
sumar los dígitos de 'num'; guardar en 'suma2'
|
||||
|
||||
/* análisis p-ádico */
|
||||
guardar 'primos' en 'temp_primos'
|
||||
iterar para(q=1, #( q<=length(temp_primos) ) , ++q )
|
||||
iterar para( r=2, #( (num % (temp_primos[q]^r)) == 0 ), ++r )
|
||||
#(temp_primos[q]); meter en 'primos'
|
||||
siguiente
|
||||
siguiente
|
||||
|
||||
sumar dígitos de cada número de 'primos'
|
||||
guardar en 'suma1'
|
||||
|
||||
'suma1' respecto a 'suma2' son iguales?
|
||||
entonces{
|
||||
_muestra número encontrado 'num'
|
||||
}
|
||||
siguiente
|
||||
terminar
|
||||
|
||||
subrutinas
|
||||
|
||||
muestra número encontrado (x)
|
||||
imprimir ( #(lpad(" ",4,string(x))), solo si ( #(i<8), " " ) )
|
||||
++i
|
||||
cuando ( #(i>8) ){
|
||||
saltar, guardar '1' en 'i'
|
||||
}
|
||||
retornar
|
||||
32
Task/Smith-numbers/EasyLang/smith-numbers.easy
Normal file
32
Task/Smith-numbers/EasyLang/smith-numbers.easy
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
proc prim_fact x . pf[] .
|
||||
pf[] = [ ]
|
||||
p = 2
|
||||
repeat
|
||||
if x mod p = 0
|
||||
pf[] &= p
|
||||
x = x div p
|
||||
else
|
||||
p += 1
|
||||
.
|
||||
until x = 1
|
||||
.
|
||||
.
|
||||
func digsum x .
|
||||
while x > 0
|
||||
sum += x mod 10
|
||||
x = x div 10
|
||||
.
|
||||
return sum
|
||||
.
|
||||
for i = 2 to 9999
|
||||
prim_fact i pf[]
|
||||
if len pf[] >= 2
|
||||
sum = 0
|
||||
for e in pf[]
|
||||
sum += digsum e
|
||||
.
|
||||
if digsum i = sum
|
||||
write i & " "
|
||||
.
|
||||
.
|
||||
.
|
||||
38
Task/Smith-numbers/SETL/smith-numbers.setl
Normal file
38
Task/Smith-numbers/SETL/smith-numbers.setl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
program smith_numbers;
|
||||
loop for s in [n : n in [2..9999] | smith(n)] do
|
||||
putchar(lpad(str s, 5));
|
||||
if (i +:= 1) mod 16=0 then print; end if;
|
||||
end loop;
|
||||
print;
|
||||
|
||||
proc smith(n);
|
||||
facs := factors(n);
|
||||
return #facs /= 1 and +/digits(n) = +/[+/digits(f) : f in facs];
|
||||
end proc;
|
||||
|
||||
proc digits(n);
|
||||
d := [];
|
||||
loop while n > 0 do
|
||||
d with:= n mod 10;
|
||||
n div:= 10;
|
||||
end loop;
|
||||
return d;
|
||||
end proc;
|
||||
|
||||
proc factors(n);
|
||||
f := [];
|
||||
loop while even n do
|
||||
n div:= 2;
|
||||
f with:= 2;
|
||||
end loop;
|
||||
d := 3;
|
||||
loop while d <= n do
|
||||
loop while n mod d = 0 do
|
||||
n div:= d;
|
||||
f with:= d;
|
||||
end loop;
|
||||
d +:= 2;
|
||||
end loop;
|
||||
return f;
|
||||
end proc;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue