Anonymous user
Smallest power of 6 whose decimal expansion contains n: Difference between revisions
Smallest power of 6 whose decimal expansion contains n (view source)
Revision as of 10:42, 8 April 2021
, 3 years ago→{{header|Pascal}}: can't imagine that PHIX tested limit -- (tested to 10,000,000)
m (→{{header|Pascal}}: can't imagine that PHIX tested limit -- (tested to 10,000,000)) |
|||
Line 92:
Doing long multiplikation like in primorial task.
<lang pascal>program PotOf6;
{$IFDEF FPC
{$MODE DELPHI}
{$OPTIMIZATION ON,ALL}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
sysutils;
const
// POT_LIMIT =
// POT_LIMIT =
// POT_LIMIT =
// POT_LIMIT =
// POT_LIMIT =
POT_LIMIT = 28;DEC_LIMIT = 22;//'14'
type
tMulElem = Uint32;
tMul = array of tMulElem;
var
PotArrN : array of tMul;▼
Pot_N_str : array of AnsiString;
function ConvToStr(const Mul:tMul):AnsiString;
const
NineZeros:string[9] ='000000000';
var
i,j : integer;
begin
setlength(result,length(MUL)*9);
i := High(Mul);
result := IntToStr(Mul[i]);
Line 117 ⟶ 126:
If i >= 0 then
repeat
// result += Format('%.9d',[Mul[i]]); takes > double time
dummy := NineZeros;
s := IntToStr(Mul[i]);
j := length(s);
move(s[1],dummy[9+1-j],j);
result += dummy;
dec(i);
until i<0;
Line 135 ⟶ 149:
Begin
prod := n*Mul[j]+Carry;
Carry := prod
result[j] := Prod - Carry*LongWordDec;
end;
Line 143 ⟶ 157:
Setlength(result,length(Mul));
end;
procedure GeneratePot_N_Str(number:NativeInt);
var
▲ PotArrN : array of tMul;
s:AnsiString;▼
i
found:Boolean;▼
Begin
setlength(Pot_N_str,POT_LIMIT+1);
setlength(PotArrN,POT_LIMIT+1);
number := 6;▼
setlength(PotArrN[0],1);
setlength(PotArrN[1],1);
Line 160 ⟶ 171:
PotArrN[1,0] := number;
Pot_N_str[1] := IntToStr(number);
//create all pot of numbers up to number**POT_LIMIT with clean up in parallel
i := 2;
while i <= POT_LIMIT do
Line 168 ⟶ 179:
setlength(PotArrN[i-1],0);
inc(i);
IF i AND 1023 = 0 then
write(i,#13);
end;
setlength(PotArrN[i-1],0);
setlength(PotArrN[0],0);
setlength(PotArrN,0);
end;
var
▲ s:AnsiString;
i,j,number,maxpos: NativeInt;
▲ found:Boolean;
Begin
GeneratePot_N_Str(number);
//Now check for first occurence str of i
maxpos := 0;
For i := 0 to DEC_LIMIT-1 do
begin
Line 182 ⟶ 204:
Begin
found := true;
If maxpos<j then
writeln(s:3,number:3,'^',j:2),' ', Pot_N_str[j]);▼
maxpos:= j;
IF POT_Limit > 99 then
write(s:3,number:3,'^',j:5,maxpos:6,#13)
else
break;
end;
Line 191 ⟶ 218:
end;
end;
writeln;
writeln('max pot :',maxpos);
// clean up strings
For j := POT_LIMIT downto 0 do
setlength(Pot_N_str[
setlength(Pot_N_str,0);
end.</lang>
{{out}}
<pre>
0 6^ 9 10077696
1 6^ 0 1
Line 219 ⟶ 249:
19 6^21 21936950640377856
20 6^26 170581728179578208256
21 6^ 3 216
max pot :28</pre>
=={{header|Phix}}==
|