Maximum Square-Free Divisor
Problem statement
Your friend gives you a positive integer n. Find the largest positive divisor d of n that is not divisible by any perfect square greater than 1.
Equivalently, d must not be divisible by k^2 for any integer k >= 2. Such a number is called square-free. Return the maximum possible d.
Function
solve(n: long) → longExamples
Example 1
n = 4return = 2The divisors of 4 are 1, 2, and 4. The divisor 4 is divisible by the perfect square 4, while 2 is square-free. Return 2.
Example 2
n = 1return = 1The only positive divisor is 1. No perfect square greater than 1 divides it, so return 1.
Example 3
n = 72return = 672 = 2^3 * 3^2. A square-free divisor can use at most one factor of 2 and one factor of 3. Taking both gives the largest valid divisor, 6.
Constraints
1 <= n <= 10^12.- The input and return value use signed 64-bit integers.