Statistics

Problem Statement for "ManyNumbers"

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

  4. {0,1,2,3,2}

    2

    Returns: 0

  5. {}

    100

    Returns: 0

  6. {}

    3

    Returns: 0

  7. {4,19,28,32}

    4

    Returns: 45

  8. {167,168,959,757,209,119}

    3

    Returns: 2043

  9. {108,999,186,735,888,105}

    3

    Returns: 3021

  10. {468,335,501,170,725,479,359,963,465,706,146,282,828,962,492,996,943,828,437,392,605,903,154,293,383,422,717,719,896,448,727,772,539,870,913,668,300,36,895,704,812,323}

    41

    Returns: 21706

  11. {665,142,712,254,869,548,645,663,758,38,860,724,742,530,779,317,36,191,843,289,107,41,943,265}

    78

    Returns: 11961

  12. {806,891,730,371,351,7,102,394,549,630,624,85,955,757,841,967,377,932,309,945,440,627,324,538,539,119,83,930,542,834,116,640,659,705,931,978,307,674,387,22,746,925,73,271,830,778,574}

    50

    Returns: 26215

  13. {987,291,162,637,356,768,656,575,32,53,351,151,942}

    45

    Returns: 5961

  14. {431,108,192,8,338,458,288,754,384,946,910,210,759,222,589,423,947}

    85

    Returns: 7967

  15. {414,169,901,592,763,656,411,360,625,538,549,484,596,42,603,351,292,837,375,21,597,22,349,200,669,485,282,735,54,1000,419}

    22

    Returns: 13379

  16. {789}

    12

    Returns: 789

  17. {729,894,649,484,808,422,311,618,814,515,310,617,936,452,601,250,520,557}

    30

    Returns: 10487

  18. {225,9,845,610}

    42

    Returns: 1689

  19. {196,486,94}

    89

    Returns: 776

  20. {588,315,504,449,201,459,619,581,797,799,282,590,799,10,158,473,623,539,293,39,180,191,658,959}

    55

    Returns: 11106

  21. {889,157,512,203,635,273,56,329,647,363,887,876,434,870,143,845}

    32

    Returns: 7095

  22. {999,323,652,22,700,558,477,893,390,76,713,601,511,4,870,862,689,402,790,256,424,3,586,183,286,89,427,618,758,833,933,170}

    77

    Returns: 16098

  23. {190,977,330,369,693,426,556,435,550,442,513,146,61,719,754,140,424,280,997,688,530,550}

    15

    Returns: 9240

  24. {950,194,196,298,417,287,106,489,283,456,735,115,702,317,672,787,264}

    58

    Returns: 7268

  25. {186,54,913,809,833,946}

    58

    Returns: 3741

  26. {322,559,647,983,482,145,197}

    28

    Returns: 3335

  27. {162,536,451,174,467,45,660,293,440,254,25,155,511,746,650,187,314,475,23,169,19,788,906,959,392,203,626,478,415,315}

    86

    Returns: 11838

  28. {875,373,160,834,71,488,298,519,178,774,271,764,669,193,986,103,481,214,628,803,100,528,626,544,925,24,973,62,182,4,433,506,594,726,32}

    79

    Returns: 15941

  29. {223,287,65,901,188,361,414,975,271,171,236,834,712,761,897,668,286,551,141,695,696,625,20,126,577,695,659,303,372,467,679,594,852,485,19,465,120,153,801,88,61,927,11}

    7

    Returns: 17248

  30. {316,577,228,44,759,165,110,883,87,566,488,578,475,626,628,630,929,424,521,903,963}

    26

    Returns: 10900

  31. {738,262,196,526,265,261,203,117,31,327,12,772,412,548,154,521,791,925,189,764,941,852,663,830,901,714,959,579,366,8,478,201,59,440,304,761,358,325,478,109,114,888,802,851,461,429,994}

    62

    Returns: 22879

  32. {541,112,705,836,357,73}

    48

    Returns: 2624

  33. {486,557,217,627,358,527,358,338,272,870,362,897,23,618,113,718,697,586,42,424,130,230,566,560}

    24

    Returns: 10576

  34. {856,54,963,585,735,655,973,458,370,533,964,608,484,912,636,68,849,676,939,224,143,755,512,742,176,460,826,222,871,627,935,206,784,851,399,280,702,194,735,638,535,557,994,177,706,963,549}

    43

    Returns: 28081

  35. {414}

    11

    Returns: 414

  36. {856,143,463,612,878,425}

    10

    Returns: 3377

  37. {444,297,674}

    43

    Returns: 1415

  38. {876,73,819,611,18,933,113,696,170,832,41,489,686,91}

    95

    Returns: 6448

  39. {991,146,354,315,652,741,45,259,336,760,193,606,265,182,504,830,776,609,293,998,550,557,562,628,468,542,130,241,814,175,602,78,216,684,214,993,825,602,393,760}

    98

    Returns: 19889

  40. {2, 4, 6 }

    2

    Returns: 12

  41. {2, 4, 1 }

    2

    Returns: 5

  42. {2, 4 }

    2

    Returns: 6

  43. {22, 42, 24, 28, 3 }

    2

    Returns: 113

  44. {4, 3 }

    2

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: