TopCoder problem "ManyNumbers" used in TCHS SRM 25 (Division I Level One)



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

0)
    
{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.
1)
    
{3,4,5,6,7,8,9,10}
5
Returns: 22
2)
    
{991,45,32,0,1,1,2}
8
Returns: 1008

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7276

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10077&pm=7276

Writer:

Vedensky

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Brute Force