#CT0000062. Bình phương hoặc lập phương (Square or Cube)
Bình phương hoặc lập phương (Square or Cube)
Square or Cube
Version: Phuoc Hung OJ Extended
Problem Statement
A positive integer is a perfect square if it has the form , and a perfect cube if it has the form , where are positive integers.
Given two positive integers and , count the integers that satisfy at least one of these conditions: is a perfect square, or is a perfect cube.
If a number is both a perfect square and a perfect cube, count it only once.
Input
One line contains two positive integers and .
Output
Print one integer: the number of values in satisfying the requirement.
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): .
Examples
Example 1
Input
1 10
Output
4
Explanation
The required values are . The value is both a square and a cube, but it is counted once.
Example 2
Input
8 64
Output
8
Explanation
The values are . The value belongs to both sets but is counted once.
Example 3
Input
64 729
Output
24
Explanation
The interval contains perfect squares and perfect cubes. The values and are in both sets. By inclusion-exclusion, the number of distinct values is .