TopcoderArchive
Archive
Algorithm problem

SquareDivisor

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a long n. Return the largest divisor of n that is a perfect square. That is, the correct return value is x if and only if:
  1. x divides n
  2. There is an integer y such that x = y*y.
  3. x is the largest integer that satisfies conditions 1 and 2.

Definition

Class:
SquareDivisor
Method:
biggest
Parameters:
long
Returns:
long
Method signature:
long biggest(long n)
(be sure your method is public)

Constraints

  • n will be between 1 and 10^18, inclusive.

Examples

  1. 12
    Returns: 4
    12 has six divisors: 1, 2, 3, 4, 6, and 12. Among them, only 1 and 4 are perfect squares. You should return the biggest one.
  2. 100
    Returns: 100
  3. 2014
    Returns: 1
  4. 999999875021574338
    Returns: 499999937510787169
  5. 999999998000000002
    Returns: 1
Back to all problems