Anonymous user
Digital root/Multiplicative digital root: Difference between revisions
Digital root/Multiplicative digital root (view source)
Revision as of 08:13, 9 December 2021
, 2 years ago→{{header|Free Pascal}}: first occurence of persistence 0..11 .Inline GetMulDigits
(→{{header|PARI/GP}}: append =={header|Pascal}}== find the first 9 brute force) |
m (→{{header|Free Pascal}}: first occurence of persistence 0..11 .Inline GetMulDigits) |
||
Line 2,042:
inspired by [[Worthwhile_task_shaving]] :-)<BR>
Brute force speed up GetMulDigits.
<lang pascal>program MultRoot;
{$IFDEF FPC}
{$MODE DELPHI}{$OPTIMIZATION ON,ALL}{$CODEALIGN proc=16}
Line 2,060 ⟶ 2,059:
end;
const
Testnumbers : array[0..
18446743999999999999,
//first occurence of persistence 0..11
var
Line 2,083 ⟶ 2,082:
end;
function GetMulDigits(n:Uint64):UInt64;inline;
var
pMul3Dgt :^tMul3Dgt;
begin
i := 1;▼
pMul3Dgt := @Mul3Dgt[0];
while n >= 1000 do
begin
q := n div 1000;
n := q;
end;
If n>=100 then
else
if n>=10 then
else
end;
Line 2,123 ⟶ 2,121:
const
var
//all initiated with 0
MulRoot:tMulRoot;
Sol : array[0..9,0..
SolIds : array[0..9] of Int32;
i,idx,mr,AlreadyDone : Int32;
BEGIN
InitMulDgt;
AlreadyDone := 10;//0..9
MulRoot.mrNum := 0;
repeat
Line 2,139 ⟶ 2,138:
mr := MulRoot.mrMul;
idx := SolIds[mr];
If idx<
begin
Sol[mr,idx]:= MulRoot;
inc(idx);
SolIds[mr]:= idx;
if idx =
dec(AlreadyDone);
end;
Line 2,153 ⟶ 2,152:
begin
write(i:3,':');
For idx := 0 to
write(Sol[i,idx].mrNum:
writeln;
end;
Line 2,172 ⟶ 2,171:
{{out|@TIO.RUN}}
<pre>
Real time:
MDR: First
0: 0 10 20 25 30 40 45 50 52
Line 2,185 ⟶ 2,184:
9: 9 19 33 91 119 133 191 313 331
number mulroot
123321 8 3
7739 8 3
Line 2,191 ⟶ 2,190:
899998 0 2
18446743999999999999 0 2
2677889 0 8
26888999 0 9
3778888999 0 10
277777788888899 0 11</pre>
=={{header|Perl}}==
|