TopcoderArchiveVisit Topcoder
SRM8 Feb 2005
SRM 230

InequalityChecker

Problem statement, definition, constraints, and public examples.

Problem Statement

Using mathematical induction it is possible to prove the following inequality when n>1:
	s = 13 + 23 + ... + (n-1)3 < n4/4 < 13 + 23 + ... + n3 = S
Given n return (S+s)/2 - n4/4 as a int[] with 2 elements. Elements 0 and 1 denote the numerator and denominator of the return value, respectively, when written in least terms (reduced).

Definition

Class:
InequalityChecker
Method:
getDifferences
Parameters:
int
Returns:
int[]
Method signature:
int[] getDifferences(int n)
(be sure your method is public)

Constraints

  • n will be between 2 and 100 inclusive.

Examples

  1. 2
    Returns: { 1,  1 }
    We have s = 1^3 = 1 S = 1^3 + 2^3 = 9 (S+s)/2 = (1+9)/2 = 5 n^4/4 = 16/4 = 4 Since 5-4 = 1, we return the fraction 1/1.
  2. 3
    Returns: { 9,  4 }
    We have s = 1^3 + 2^3 = 9 S = 1^3 + 2^3 + 3^3 = 36 (S+s)/2 = 45/2 n^4/4 = 81/4 We return the fraction 9/4.
  3. 100
    Returns: { 2500,  1 }
    Largest case.
Back to all problems