Last Friend Standing
All submissions for this problem are available.
Mark and his classmates were playing a game called “last man standing”. The last person left would have to be treated by the rest. The game went like this. From among n of his classmates, numbered 1, 2,...,n, standing in a circle every mth person is going to be disqualified. Mark is smart enough to choose the position of the last remaining person, thus always getting a treat. Now to make the game more fun he wanted his friends to last longer than the rest of his classmates. In the circle the first p are his good friends and the last p, his other classmates. You have to determine a minimal m such that all his other classmates will be out of the game before the first friend.
The first line contains t, the number of test cases (1<=t<=100). The following t lines have a positive integer p (1<=p<14)
The output file will consist of t lines, each containing the integer m corresponding to p in the input file.
Input: 2 3 4 Output: 5 30
Note : This problem has been taken from previously solved problems.
|Time Limit:||1 - 3 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.