Sum of cubes of divisors of numbers in a range using the Sieve of Eratosthenes

PHP Hard math

Task «Sum of cubes of divisors of numbers in a range using the Sieve of Eratosthenes»

Given two natural numbers A and B (A ≤ B). For each number N in the range from A to B, find the sum of the cubes of its divisors. Output the count of numbers N for which the resulting sum is a perfect square. Use an optimized sieve to compute the sum of cubes of divisors for all numbers in O(B log B). Constraints: 1 ≤ A ≤ B ≤ 10^6.

Input Format

Two integers A and B, separated by a space.

Output Format

One integer — the count of numbers N in the range [A, B] for which the sum of the cubes of divisors is a perfect square.

main.php