Submit | All submissions | Best solutions | Back to list |
GUESSTHE - Guess the Number |
You are playing the funny game “Guess the number” with a friend. In this game, one of the players choose a positive integer and the other has to guess it by using the clues that are revealed. The i-th clue is either “Y” or “N” indicating whether the hidden number is a multiple of i or not, respectively. For instance, if the clues so far are “YYNYY” it means that the number is a multiple of 1, 2, 4 and 5, but it is not a multiple of 3. Given the clues of the game so far, you have to guess the minimum possible number according to them, or call your friend a cheater if there is no number such that the clues were correctly given.
Input
The input contains several test cases. Each test case is described in a single line that contains a non-empty string of at most 20 characters. The string is formed entirely of uppercase letters “Y” and “N”, and represents the clues given so far, in order from left to right. The last line of the input contains a single asterisk and should not be processed as a test case.
Output
For each test case output a single line with the minimum positive integer that satisfies all the clues, or −1 if there is no such a number.
Example
Input: YYNYY YYYNNN * Output: 20 -1
Added by: | Pablo Ariel Heiber |
Date: | 2010-08-19 |
Time limit: | 2.950s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS OBJC PERL6 VB.NET |
Resource: | FCEyN UBA ICPC Selection 2008 |
hide comments
|
|||||||
2015-01-19 16:09:43 eightnoteight
this one irritated me alot, but finally did it.. yeah! this is an excellent problem... |
|||||||
2014-02-02 08:50:36 headfirstcoder
NOTE: More Than 20 Characters can also be used... |
|||||||
2013-10-27 20:34:53 Martijn Muijsers
For certain algorithms you will need to use long long int... ;) |
|||||||
2013-06-16 20:33:56 DEBANJAN GHOSH
Hi every time i am getting runtime error (SIGSEGV). It is running fine inIdeone for all test cases.Please suggest |
|||||||
2013-04-08 23:02:43 Shubham upadhaya
OK Last edit: 2013-04-08 23:11:45 |
|||||||
2013-02-04 12:40:40 Meraj Ahmed
test cases please @Pablo Ariel Heiber: plz check my solution, ID: 8652351 Last edit: 2013-02-04 12:51:08 |
|||||||
2012-10-10 12:39:10 Asheesh Ranjan
Should there be a newline at the end of output? Also,is there a newline at the end of input ? |
|||||||
2012-10-03 18:35:38 sachin kumar
i am gettting runtime error.but it is working in ideone.com |
|||||||
2012-09-20 19:24:24 BLANKRK
easy one!!! |