TopcoderArchiveVisit Topcoder
SRM22 Dec 2013
SRM 625

AddMultiply

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given an int y. We are looking for any int[] x that satisfies the following constraints:
  • x has exactly three elements
  • ( x[0] * x[1] ) + x[2] = y
  • Each x[i] must be between -1000 and 1000, inclusive.
  • No x[i] can be equal to 0 or 1.
Find and return one such x.

If there are multiple valid solutions, you may return any of them. You may assume that for our constraints on y (specified below) at least one valid x always exists.

Definition

Class:
AddMultiply
Method:
makeExpression
Parameters:
int
Returns:
int[]
Method signature:
int[] makeExpression(int y)
(be sure your method is public)

Constraints

  • y will be between 0 and 500, inclusive.

Examples

  1. 6
    Returns: {2, 2, 2 }
    2*2 + 2 = 6 Note that this is one of many possible solutions. Another solution is: 3*3 + (-3) = 6
  2. 11
    Returns: {2, 3, 5 }
  3. 0
    Returns: {7, 10, -70 }
    Note that 0 and 1 are not allowed, thus a result like 0 * 0 + 0 would be incorrect.
  4. 500
    Returns: {-400, -3, -700 }
    Some or all of the returned numbers may be negative.
  5. 2
    Returns: {2, 2, -2 }
  6. 5
    Returns: {5, 2, -5 }
Back to all problems