Statistics

Problem Statement for "LotsOfLines"

Problem Statement

Note that the memory limit for all tasks in this SRM is 256 MB.

You are given ints A and B. These determine a set of A*B lines in the plane: for each pair of integers (a,b) such that 0 <= a < A and 0 <= b < B, there is a line with the equation y=ax+b.

These lines divide the plane into several regions. (Some of them are finite, some are infinite.) Compute and return the total number of regions.

Definition

Class:
LotsOfLines
Method:
countDivisions
Parameters:
int, int
Returns:
long
Method signature:
long countDivisions(int A, int B)
(be sure your method is public)

Notes

  • Formally, the line with the equation y=ax+b is the set of all points (x,y) such that x is any real number and y=ax+b.

Constraints

  • A will be between 1 and 1,200, inclusive.
  • B will be between 1 and 1,200, inclusive.

Examples

  1. 1

    1

    Returns: 2

    There is only one line: y=0. This line divides the plane into two regions.

  2. 2

    2

    Returns: 9

    There are four lines. The plane looks as follows.

  3. 3

    2

    Returns: 17

  4. 1

    1200

    Returns: 1201

    There are 1,200 horizontal lines.

  5. 5

    9

    Returns: 638

  6. 500

    500

    Returns: 18997978639

  7. 1200

    1200

    Returns: 630301012623

  8. 1199

    1200

    Returns: 629250802361

  9. 1200

    1199

    Returns: 629250802362

  10. 1200

    1

    Returns: 2400

  11. 1

    1200

    Returns: 1201

  12. 1

    1

    Returns: 2

  13. 2

    1

    Returns: 4

  14. 3

    1

    Returns: 6

  15. 1

    2

    Returns: 3

  16. 2

    2

    Returns: 9

  17. 3

    2

    Returns: 17

  18. 1

    3

    Returns: 4

  19. 2

    3

    Returns: 16

  20. 3

    3

    Returns: 32

  21. 150

    138

    Returns: 130256183

  22. 88

    37

    Returns: 3223300

  23. 96

    29

    Returns: 2354936

  24. 74

    200

    Returns: 66583275

  25. 5

    45

    Returns: 15074

  26. 1191

    1169

    Returns: 589217910486

  27. 1139

    1179

    Returns: 548149275716

  28. 1162

    1155

    Returns: 547520250746

  29. 1165

    1112

    Returns: 510134349553

  30. 1139

    1140

    Returns: 512484902549

  31. 1112

    1178

    Returns: 521583006399

  32. 1193

    1143

    Returns: 565192984788

  33. 1194

    1132

    Returns: 555296584641

  34. 1194

    1149

    Returns: 572100259808

  35. 1181

    1101

    Returns: 513921912602

  36. 44

    1135

    Returns: 757813108

  37. 97

    1107

    Returns: 3504413828

  38. 84

    1132

    Returns: 2748398323

  39. 90

    1105

    Returns: 3006485588

  40. 43

    1174

    Returns: 774064727

  41. 1151

    29

    Returns: 338156898

  42. 1158

    10

    Returns: 40560915

  43. 1152

    40

    Returns: 645197883

  44. 1111

    60

    Returns: 1350423181

  45. 1102

    48

    Returns: 850309279

  46. 1122

    1122

    Returns: 481719582617


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: