A multiplication game(POJ-2505)

题面

Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p >= n.

输入

Each line of input contains one integer number n.

输出

For each line of input output one line either Stan wins. or Ollie wins. assuming that both of them play perfectly.

样例输入

1162
217
334012226

样例输出

1Stan wins.
2Ollie wins.
3Stan wins.

提示

思路

找出先手必败区间(9, 18],(162, 324],$ \ldots $

规律: 9 = 9 18 = 2 * 9 162 = 9 * 2 * 9 324 = 2 * 9 * 2 * 9 $ \ldots $

代码

 1using namespace std;
 2typedef long long LL;
 3
 4int main()
 5{
 6    LL n;
 7    while(~scanf("%lld", &n) && n)
 8    {
 9        while(1){
10            if(n<=9){
11                printf("Stan wins.\n");
12                break;
13            }else if(n<=18){
14                printf("Ollie wins.\n");
15                break;
16            }
17            n = (LL)ceil(n/18.0);
18        }
19    }
20    return 0;
21}