Anonymous user
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 21:37, 15 January 2020
, 4 years ago→alternative: on steroids ;-) astonishing that only the first 17 digits needed to get the right first digits after 193E6 calculations
m (→{{header|Pascal}}: alternative only using one Uint64) |
m (→alternative: on steroids ;-) astonishing that only the first 17 digits needed to get the right first digits after 193E6 calculations) |
||
Line 160:
function FindExp(CntLmt:NativeUint;Number : AnsiString):NativeUint;
var
probe,dgts : Uint64;
i,cnt,n: NativeUInt;
begin
dgts := 1;
For i := 1 to 18-Length(Number) do
dgts *=10;
n := StrToInt(Number);
cnt := 0;
i := 0;
Line 169 ⟶ 173:
inc(Probe,Probe);
inc(i);
If Probe >= 1000*1000*1000 *1000*1000*1000 then
repeat
Probe := Probe DIV 10;▼
If Probe >= 1000*1000*1000 *1000*1000*1000 then
▲ Probe := Probe DIV 10;
// get rid of converting into string
IF Probe DIV dgts = n then
Begin
inc(cnt);
IF cnt>= CntLmt then
Begin
DEC(cnt);// because the BREAK in the next IF
BREAK;
end;
end;
inc(Probe,Probe);
inc(i);
until false;
IF COPY(IntToStr(Probe),1,Length(number)) = Number then
Begin
Line 195 ⟶ 213:
end.</lang>
{{out}}
<pre>
The 2th occurrence of 2 raised to a power whose product starts with "12" is 80
The 45th occurrence of 2 raised to a power whose product starts with "123" is 12,710
Line 201 ⟶ 220:
The 678,910th occurrence of 2 raised to a power whose product starts with "123" is 193,060,223
real
=={{header|REXX}}==
|