First power of 2 that has leading decimal digits of 12: Difference between revisions

m
→‎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 2**i gets to big divide by one digit = 10
If Probe >= 1000*1000*1000 *1000*1000*1000 then
repeat
Probe := Probe DIV 10;
If Probe >= 1000*1000*1000 *1000*1000*1000 then
//Check the first characters of the number
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>
<pre>The 1th occurrence of 2 raised to a power whose product starts with "12" is 7
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 0m22 0m0,931s981s</pre>
//Without IF COPY(IntToStr(Probe),1,Length(number)) = Number then
FindExp(193060223,'123') takes
real 0m0,212s</pre>
 
=={{header|REXX}}==
Anonymous user