Advertisement
regergr

Untitled

Oct 30th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. program project1;
  2.  
  3. var
  4. a, b, pmax, pmin, Count: QWord;
  5. n: integer;
  6.  
  7. function Exp(x: qword; n1: integer): qword;
  8. var
  9. c, last: qword;
  10. overflow: boolean;
  11. const
  12. sqrt_qword = 4294967297;
  13. begin
  14. overflow := False;
  15. c := 1;
  16. while n1 <> 0 do
  17. begin
  18. if n1 mod 2 = 1 then
  19. begin
  20. last := c;
  21. c := c * x;
  22. if (c = 0) or (x = 0) then
  23. begin
  24. overflow := True;
  25. break;
  26. end;
  27. if (c div x <> last) then
  28. overflow := True;
  29. end;
  30. if (x >= sqrt_qword) and (n1 > 1) then
  31. overflow := True;
  32. x := x * x;
  33. n1 := n1 div 2;
  34. end;
  35. if overflow then
  36. c := high(qword);
  37. Result := c;
  38. end;
  39.  
  40. function SearchMax(x, n: QWord): QWord;
  41. var
  42. l, r, m: QWord;
  43. begin
  44. r:=x div 2;
  45. l := 2;
  46. m := l+(r - l) div 2;
  47. while (r - l > 1) do
  48. begin
  49. m := (l + r) div 2;
  50. if (Exp(m, n) >= x) then
  51. r := m
  52. else
  53. l := m;
  54.  
  55. end;
  56. while (Exp(r, n) > x) and (x <> high(qword)) do
  57. begin
  58. r := r - 1;
  59. end;
  60. Result := r;
  61. end;
  62.  
  63. function SearchMin(x, n: Qword): QWord;
  64. var
  65. l, r, m: QWord;
  66. begin
  67. r := x div 2;
  68. l := 2;
  69. while (r - l > 1) do
  70. begin
  71. m := l+(r-l) div 2;
  72. if (Exp(m, n) < x) then
  73. begin
  74. l := m;
  75. end
  76. else
  77. begin
  78. r := m;
  79. end;
  80.  
  81. end;
  82. while (Exp(l, n) < x) do
  83. begin
  84. l := l + 1;
  85. end;
  86. Result := l;
  87. end;
  88.  
  89. begin
  90. Assign(input, 'input.txt');
  91. Assign(output, 'output.txt');
  92. reset(input);
  93. rewrite(output);
  94. Read(a, b);
  95. pmin := 0;
  96. pmax := 0;
  97. Count := 0;
  98. n := 2;
  99.  
  100. while (Exp(2, n)<=b) do
  101. begin
  102.  
  103. pmax := SearchMax(b, n);
  104. pmin := SearchMin(a, n);
  105. Count := Count + (pmax - pmin) + 1;
  106. n:=n+1;
  107. end;
  108. if b = high(qword) then count -= 1;
  109. Write(Count);
  110. readln;
  111. readln;
  112. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement