Statistics

Problem Statement for "ArithSeq"

Problem Statement

An arithmetic sequence of length n is a sequence of n numbers in which the difference between each pair of adjacent numbers is some constant delta. For example, the sequence 1,6,11,16 is an arithmetic sequence of length 4 with delta=5. Now, consider the infinite set

    { 1, 3, 4, 7, 8, 9, ... }
This set is of particular interest to mathematicians because it contains arbitrarily long arithmetic sequences for any delta, yet it contains no infinitely long arithmetic sequences. The set is contructed by keeping or dropping successive groups of positive integers according to the following pattern: keep one (1), drop one (2), keep two (3,4), drop two (5,6), keep three (7,8,9), drop three (10,11,12), and so on.

Given n and delta, your task is to find the earliest arithmetic sequence contained in the set that has the given length and delta. In other words, you should find the smallest number A such that all integers of the form A+i*delta are in the set, for all i between 0 and n-1, inclusive. You should return A.

Definition

Class:
ArithSeq
Method:
minStart
Parameters:
int, int
Returns:
long
Method signature:
long minStart(int n, int delta)
(be sure your method is public)

Constraints

  • n is between 2 and 30, inclusive.
  • delta is between 1 and 100000000, inclusive.

Examples

  1. 3

    3

    Returns: 1

    The sequence is 1, 4, 7.

  2. 5

    12

    Returns: 9

  3. 6

    12

    Returns: 3661

  4. 30

    4130

    Returns: 1001001

  5. 30

    100000000

    Returns: 670380219057

  6. 30

    100

    Returns: 8412901

  7. 30

    4127

    Returns: 1001001

  8. 30

    421

    Returns: 149071891

  9. 30

    422

    Returns: 38613

  10. 30

    449

    Returns: 169559463

  11. 30

    3365

    Returns: 2687961

  12. 30

    3366

    Returns: 660157

  13. 5

    197073

    Returns: 1

  14. 6

    12345678

    Returns: 34411

  15. 20

    1010101

    Returns: 70790917

  16. 23

    100000000

    Returns: 37200659057

  17. 23

    98765432

    Returns: 36568808127

  18. 2

    1

    Returns: 3

  19. 30

    1

    Returns: 871

  20. 20

    19

    Returns: 130683

  21. 5

    5

    Returns: 421

  22. 10

    20

    Returns: 32581

  23. 20

    10

    Returns: 36291

  24. 8

    72788984

    Returns: 362359

  25. 9

    23943966

    Returns: 159601

  26. 17

    70943590

    Returns: 45304041

  27. 14

    49708334

    Returns: 14173803

  28. 17

    75093584

    Returns: 18100771

  29. 9

    92268860

    Returns: 636147

  30. 17

    35773335

    Returns: 278954098

  31. 26

    99727298

    Returns: 536457367057

  32. 20

    98294672

    Returns: 4939276741

  33. 22

    45307202

    Returns: 12794700279

  34. 20

    47871914

    Returns: 10449872309

  35. 9

    77995986

    Returns: 307471

  36. 25

    16297485

    Returns: 45786370507

  37. 21

    5558261

    Returns: 8525475223

  38. 26

    82361186

    Returns: 412991953381

  39. 29

    90794986

    Returns: 552581859523

  40. 15

    11975572

    Returns: 113565249

  41. 11

    51005214

    Returns: 1637857

  42. 19

    13364526

    Returns: 503952219

  43. 25

    25314000

    Returns: 82439904253

  44. 29

    27691612

    Returns: 113650905763

  45. 17

    14862332

    Returns: 1882496821

  46. 26

    36149331

    Returns: 141332763307

  47. 15

    6811730

    Returns: 1066057

  48. 27

    40799902

    Returns: 172790278081

  49. 26

    64698373

    Returns: 299811550051

  50. 28

    68352792

    Returns: 358575212533

  51. 26

    4878565

    Returns: 10265438443

  52. 4

    53583664

    Returns: 27723

  53. 15

    81639339

    Returns: 14061810

  54. 4

    82244019

    Returns: 31153

  55. 6

    72005180

    Returns: 121671

  56. 9

    12080287

    Returns: 202429

  57. 24

    85353684

    Returns: 30036254035

  58. 17

    44975677

    Returns: 4458729102

  59. 11

    22660161

    Returns: 78681

  60. 19

    93247632

    Returns: 11939918317

  61. 14

    75523134

    Returns: 12716335

  62. 30

    57951147

    Returns: 321937653421

  63. 30

    68778248

    Returns: 404544973483

  64. 30

    92187448

    Returns: 588829859257

  65. 30

    86079769

    Returns: 549385593231

  66. 30

    72640132

    Returns: 435009500257

  67. 30

    24924546

    Returns: 107179301307

  68. 30

    34526845

    Returns: 160673908123

  69. 30

    85502222

    Returns: 542035349131

  70. 30

    48670653

    Returns: 256313869351

  71. 30

    98050053

    Returns: 644475798057

  72. 30

    65164912

    Returns: 376970826421

  73. 30

    100000000

    Returns: 670380219057

  74. 9

    3144

    Returns: 81


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: