TopcoderArchive
Archive30 Jul 2007
TCCC07 Round 2

PowerOfInteger

Problem statement, definition, constraints, and public examples.

Problem Statement

A number y is said to be the k-th power of a number x if y = x^k, i.e., y is the product of k copies of x.

You are given two Strings left and right. Return the greatest k such that there is an integer y (left <= y <= right) such that y is the k-th power of some integer x.

Definition

Class:
PowerOfInteger
Method:
greatestPower
Parameters:
String, String
Returns:
int
Method signature:
int greatestPower(String left, String right)
(be sure your method is public)

Constraints

  • left will be an integer between 2 and 10^12, inclusive, without extra leading zeroes.
  • right will be an integer between left and 10^12, inclusive, without extra leading zeroes.

Examples

  1. "5"
    "20"
    Returns: 4
    The greatest power between 5 and 20 is 16=2^4.
  2. "10"
    "12"
    Returns: 1
    No nontrivial power of integer between 10 and 12, so return 1.
  3. "2"
    "100"
    Returns: 6
  4. "1000000000000"
    "1000000000000"
    Returns: 12
Back to all problems