Sort 48 Discussions, By:
Please Login in order to post a comment
For those who are not using Java to solve this problem, the following is some related source code from the java.util.Random library. ;)
public synchronized void setSeed(long seed)
this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1);
haveNextNextGaussian = false;
protected synchronized int next(int bits)
seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
return (int) (seed >>> (48 - bits));
public int nextInt(int n)
if (n <= 0)
throw new IllegalArgumentException("n must be positive");
if ((n & -n) == n) // i.e., n is a power of 2
return (int) ((n * (long) next(31)) >> 31);
int bits, val;
bits = next(31);
val = bits % n;
while (bits - val + (n - 1) < 0);
Test case #4 clearly violates the definition of the problem. In the description it says "The first line of input is a number N<10..." while Test case #4 provides exactly 10 test cases.
Is it even possible to solve this challenge in C++?
Couldn't help but notice that all the submitted codes for this problem do not match the current problem statement input, they had extra "start time" and "end time" inputs which makes the problem much easier. Has anybody solved this problem lately without these inputs?
Is it even possible to solve this challenge in Python?