import
java.util.*;
public
class
Main {
static
final
int
N =
1000005
;
static
final
double
MAX = 1e18;
static
ArrayList<Long> powers =
new
ArrayList<>();
static
TreeSet<Long> squares =
new
TreeSet<>();
static
TreeSet<Long> s =
new
TreeSet<>();
public
static
void
powersPrecomputation()
{
for
(
long
i =
2
; i < N; i++) {
squares.add(i * i);
if
(squares.contains(i))
continue
;
long
temp = i;
while
(i * i <= MAX / temp) {
temp *= (i * i);
s.add(temp);
}
}
powers.addAll(s);
}
public
static
long
calculateAnswer(
long
L,
long
R)
{
long
perfectSquares
= (
long
)(Math.floor(Math.sqrt(R))
- Math.floor(Math.sqrt(L -
1
)));
int
high = upperBound(powers, R);
int
low = lowerBound(powers, L);
perfectSquares += (high - low);
return
perfectSquares;
}
public
static
int
upperBound(ArrayList<Long> arr,
long
value)
{
int
l =
0
, r = arr.size();
while
(l < r) {
int
mid = l + (r - l) /
2
;
if
(arr.get(mid) <= value) {
l = mid +
1
;
}
else
{
r = mid;
}
}
return
l;
}
public
static
int
lowerBound(ArrayList<Long> arr,
long
value)
{
int
l =
0
, r = arr.size();
while
(l < r) {
int
mid = l + (r - l) /
2
;
if
(arr.get(mid) < value) {
l = mid +
1
;
}
else
{
r = mid;
}
}
return
l;
}
public
static
void
main(String[] args)
{
powersPrecomputation();
long
L =
12
;
long
R =
29
;
System.out.println(
"Number of powers between "
+ L
+
" and "
+ R +
" = "
+ calculateAnswer(L, R));
L =
1
;
R = 100000000000L;
System.out.println(
"Number of powers between "
+ L
+
" and "
+ R +
" = "
+ calculateAnswer(L, R));
}
}