First power of 2 that has leading decimal digits of 12: Difference between revisions
First power of 2 that has leading decimal digits of 12 (view source)
Revision as of 15:16, 12 March 2021
, 3 years agoFix pascal version to run in delphi
MaiconSoft (talk | contribs) (Fix pascal version to run in delphi) |
|||
Line 982:
uses
sysutils,
strUtils;
const
{$IFDEF FPC}
ld10= ln(2)/ln(10);// thats 1/log2(10)▼
{$MODE DELPHI}
▲ ld10 :double = ln(2)/ln(10);// thats 1/log2(10)
{$ELSE}
ld10 = 0.30102999566398119521373889472449;
function
var
i,
begin
i := Length(S);
//calc how many Digits needed ▼
Result := S;
NA := 0;
while (i > 0) do
begin
if ((Length(Result) - i + 1 - NA) mod 3 = 0) and (i <> 1) then
begin
insert(',', Result, i);
inc(NA);
end;
Dec(i);
end;
end;
{$ENDIF}
function FindExp(CntLmt, Number: NativeUint): NativeUint;
var
i, cnt, DgtShift: NativeUInt;
begin
i := Number;
DgtShift := 1;
while i >= 10 do
DgtShift
i := i div 10;
end;
Line 1,005 ⟶ 1,032:
// x= i*ld10 -> 2^I = 10^x
// 10^frac(x) -> [0..10[ = exp(ln(10)*frac(i*lD10))
inc(cnt);
BREAK;
end;
until false;
write('The ', Numb2USA(IntToStr(cnt)), 'th occurrence of 2 raised to a power');
write(' whose product starts with "', Numb2USA(IntToStr(
writeln('" is ', Numb2USA(IntToStr(i)));
FindExp := i;
end;
begin
FindExp(1, 12);
FindExp(2, 12);
FindExp(45, 123);
FindExp(12345, 123);
FindExp(678910, 123);
end.</lang>
{{out}}
|