MagicStonesStore
SRM 526.5 · 2011-12-12 · by cgy4ever
Problem Statement
The currency in the land of reindeer are magic stones. Santa's reindeer have 2n magic stones (i.e., an even number of them). They want to divide the stones into two piggy banks. Santa's reindeer are very fond of primes, therefore they want each piggy bank to contain a prime number of magic stones.
You are given an
Notes
- A positive integer is prime if and only if it has exactly two positive integer divisors. The first few prime numbers are 2, 3, 5, 7, 11, ...
- The number zero is not a prime number, hence you are not allowed to leave any piggy bank empty.
Constraints
- n will be between 1 and 1,000, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
1 Returns: "NO"
As n=1, we are dividing 2 magic stones into two piggy banks. In this case is impossible to have a prime number of stones in each piggy bank.
2 Returns: "YES"
The only valid way of dividing the stones in this case is to put 2 magic stones into each of the piggy banks.
3 Returns: "YES"
Now the only way is to put 3 magic stones into each of the piggy banks.
5 Returns: "YES"
For 2n=10 stones we have two valid ways of dividing them: either as 5 + 5 or as 7 + 3.
1 Returns: "NO"
Submissions are judged against all 135 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MagicStonesStore with a public method string ableToDivide(int n) · 135 test cases · 2 s / 256 MB per case