Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program project1;
- var
- a, b, pmax, pmin, Count: QWord;
- n: integer;
- function Exp(x: qword; n1: integer): qword;
- var
- c, last: qword;
- overflow: boolean;
- const
- sqrt_qword = 4294967297;
- begin
- overflow := False;
- c := 1;
- while n1 <> 0 do
- begin
- if n1 mod 2 = 1 then
- begin
- last := c;
- c := c * x;
- if (c = 0) or (x = 0) then
- begin
- overflow := True;
- break;
- end;
- if (c div x <> last) then
- overflow := True;
- end;
- if (x >= sqrt_qword) and (n1 > 1) then
- overflow := True;
- x := x * x;
- n1 := n1 div 2;
- end;
- if overflow then
- c := high(qword);
- Result := c;
- end;
- function SearchMax(x, n: QWord): QWord;
- var
- l, r, m: QWord;
- begin
- r:=x div 2;
- l := 2;
- m := l+(r - l) div 2;
- while (r - l > 1) do
- begin
- m := (l + r) div 2;
- if (Exp(m, n) >= x) then
- r := m
- else
- l := m;
- end;
- while (Exp(r, n) > x) and (x <> high(qword)) do
- begin
- r := r - 1;
- end;
- Result := r;
- end;
- function SearchMin(x, n: Qword): QWord;
- var
- l, r, m: QWord;
- begin
- r := x div 2;
- l := 2;
- while (r - l > 1) do
- begin
- m := l+(r-l) div 2;
- if (Exp(m, n) < x) then
- begin
- l := m;
- end
- else
- begin
- r := m;
- end;
- end;
- while (Exp(l, n) < x) do
- begin
- l := l + 1;
- end;
- Result := l;
- end;
- begin
- Assign(input, 'input.txt');
- Assign(output, 'output.txt');
- reset(input);
- rewrite(output);
- Read(a, b);
- pmin := 0;
- pmax := 0;
- Count := 0;
- n := 2;
- while (Exp(2, n)<=b) do
- begin
- pmax := SearchMax(b, n);
- pmin := SearchMin(a, n);
- Count := Count + (pmax - pmin) + 1;
- n:=n+1;
- end;
- if b = high(qword) then count -= 1;
- Write(Count);
- readln;
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement