Statistics

Problem Statement for "PlayingWithPlanks"

Problem Statement

You are given a plank of length plankLength. You want to cut the plank into exactly pieces pieces such that the length of each piece is a (positive) integer and all the lengths are distinct.

If it is possible to cut the plank in the described way, return "possible". Otherwise return "impossible".

Definition

Class:
PlayingWithPlanks
Method:
canItBeDone
Parameters:
int, int
Returns:
String
Method signature:
String canItBeDone(int plankLength, int pieces)
(be sure your method is public)

Notes

  • Note that the return value is case-sensitive.

Constraints

  • plankLength will be between 1 and 1,000,000, inclusive.
  • pieces will be between 1 and 1,000, inclusive.

Examples

  1. 9

    3

    Returns: "possible"

    One possibility is to cut the plank into pieces of lengths 1, 3 and 5.

  2. 12

    1

    Returns: "possible"

  3. 9

    4

    Returns: "impossible"

    It can be shown that there is no way to cut a plank of length 9 into 4 pieces of different integer lengths.

  4. 10

    4

    Returns: "possible"

  5. 750932

    901

    Returns: "possible"

  6. 54

    10

    Returns: "impossible"

  7. 1

    1000

    Returns: "impossible"

  8. 1000000

    1

    Returns: "possible"

  9. 1000000

    1000

    Returns: "possible"

  10. 1000

    1000

    Returns: "impossible"

  11. 1

    1

    Returns: "possible"

  12. 550000

    1000

    Returns: "possible"

  13. 500500

    1000

    Returns: "possible"

  14. 500409

    1000

    Returns: "impossible"

  15. 500409

    999

    Returns: "possible"

  16. 1000

    44

    Returns: "possible"

  17. 1000

    45

    Returns: "impossible"

  18. 1036

    45

    Returns: "possible"

  19. 1035

    45

    Returns: "possible"

  20. 700001

    1000

    Returns: "possible"

  21. 200017

    632

    Returns: "impossible"

  22. 200017

    631

    Returns: "possible"

  23. 200017

    1

    Returns: "possible"

  24. 2

    2

    Returns: "impossible"

  25. 3

    2

    Returns: "possible"

  26. 4

    3

    Returns: "impossible"

  27. 7

    2

    Returns: "possible"

  28. 5

    5

    Returns: "impossible"

  29. 9

    9

    Returns: "impossible"

  30. 500499

    1000

    Returns: "impossible"

  31. 4

    4

    Returns: "impossible"


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: