TopcoderArchive
Archive
Algorithm problem

ManyNumbers

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given a int[] numbers and an int K. Let A be the sum of all values in numbers divisible by K, and let B be the sum of all values not visible by K. Return the absolute value of the difference between A and B.

Definition

Class:
ManyNumbers
Method:
getSums
Parameters:
int[], int
Returns:
int
Method signature:
int getSums(int[] numbers, int K)
(be sure your method is public)

Constraints

  • numbers will contain between 0 and 50 elements, inclusive.
  • Each element in numbers will be between 0 and 1000, inclusive.
  • K will be between 2 and 100, inclusive.

Examples

  1. {2,3,4,5,6}
    3
    Returns: 2
    The sum of the values that are divisible by 3 is 3+6 = 9. The sum of the values not divisible by 3 is 2+4+5 = 11.
  2. {3,4,5,6,7,8,9,10}
    5
    Returns: 22
  3. {991,45,32,0,1,1,2}
    8
    Returns: 1008
Back to all problems