Statistics

Problem Statement for "StairsColoring"

Problem Statement

A very rich sultan built an enormous luxurious two-story palace containing several staircases. According to an old tradition, each staircase must:

  • contain exactly N steps
  • have a right angle in its base
  • be built using exactly N rectangular blocks of arbitrary size

Staircases can be built using many different arrangements of blocks. For example, there are 5 ways to build a staircase with 3 steps:

To ensure that his palace is really the most luxurious in the world, the sultan decided to build one staircase for each possible arrangement of blocks.


The sultan is now preparing for a staircase coloring festival. He wants to paint each of the staircases in the palace in one of K different colors. Multiple staircases can be painted the same color, and it is not necessary to use all K colors. Help the sultan by calculating the total number of different ways he can color his staircases. The answer can be large, so return the count modulo 1000000123.

Definition

Class:
StairsColoring
Method:
coloringCount
Parameters:
int, int
Returns:
int
Method signature:
int coloringCount(int N, int K)
(be sure your method is public)

Constraints

  • N will be between 1 and 1000000000, inclusive.
  • K will be between 1 and 1000000000, inclusive.

Examples

  1. 3

    2

    Returns: 32

    As shown in the picture above, there are exactly 5 different ways to build a staircase with 3 steps. Each staircase can be painted in one of 2 different colors, for a total of 32 possible color combinations.

  2. 2

    2

    Returns: 4

  3. 1

    1

    Returns: 1

    Here, there is only one staircase and one color to paint it.

  4. 4

    5

    Returns: 103514887

  5. 7

    77

    Returns: 747707397

  6. 1000000000

    123

    Returns: 1

  7. 1000000000

    1000000000

    Returns: 1

  8. 536870911

    1000000000

    Returns: 543724762

  9. 123456789

    1

    Returns: 1

  10. 268435455

    36648724

    Returns: 208048256

  11. 134217727

    36648724

    Returns: 1

  12. 117825866

    7457346

    Returns: 13498530

  13. 387420488

    84069467

    Returns: 806796213

  14. 643076642

    123

    Returns: 214970630

  15. 279

    562444338

    Returns: 47154375

  16. 11

    358206529

    Returns: 857359266

  17. 362

    863193754

    Returns: 274995007

  18. 120

    438119233

    Returns: 437630283

  19. 256

    689481272

    Returns: 90697485

  20. 8775

    278000423

    Returns: 572861679

  21. 2938

    487044242

    Returns: 410078719

  22. 7273

    610019679

    Returns: 711942185

  23. 3047

    259939330

    Returns: 832431563

  24. 8752

    679078961

    Returns: 618152009

  25. 959349

    298165444

    Returns: 373912105

  26. 271825

    558967608

    Returns: 728819731

  27. 604088

    872931663

    Returns: 755962687

  28. 754447

    686456775

    Returns: 372431019

  29. 848707

    623629290

    Returns: 224104687

  30. 930552

    186804456

    Returns: 237516386

  31. 197350

    232952234

    Returns: 974852665

  32. 798144

    717319524

    Returns: 887479123

  33. 840344

    311701756

    Returns: 356084284

  34. 712455

    435488855

    Returns: 747050769

  35. 280179047

    138284830

    Returns: 144167434

  36. 489152343

    650268386

    Returns: 807372474

  37. 131266783

    482122404

    Returns: 973886042

  38. 909833560

    572746703

    Returns: 377020583

  39. 214776896

    461181366

    Returns: 2124231

  40. 477365003

    637517399

    Returns: 705347008

  41. 439584539

    933502299

    Returns: 646156402

  42. 685949640

    579379272

    Returns: 414936531

  43. 319453138

    683268749

    Returns: 245072125

  44. 684365003

    308843531

    Returns: 43749586

  45. 999988776

    2

    Returns: 676672996

  46. 999999999

    3

    Returns: 1

  47. 999999997

    4

    Returns: 1

  48. 1000000000

    5

    Returns: 1

  49. 888888888

    6

    Returns: 1

  50. 999999997

    999999997

    Returns: 1

  51. 1000000000

    500000000

    Returns: 1

  52. 326402540

    326402540

    Returns: 113950251

  53. 987558789

    987558789

    Returns: 787202130

  54. 100028703

    2

    Returns: 133309173

  55. 46248482

    7189719

    Returns: 1

  56. 999998743

    999998742

    Returns: 345389292

  57. 423531123

    8013

    Returns: 223632865

  58. 11000

    2645743

    Returns: 798025601

  59. 100000000

    599111111

    Returns: 1

  60. 999999991

    999999973

    Returns: 1

  61. 24

    2

    Returns: 440011672

  62. 123

    9999

    Returns: 885229876

  63. 3627

    2

    Returns: 1

  64. 985575155

    1337731

    Returns: 1

  65. 131071

    2

    Returns: 596907532


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: