Test instructions: Stan starts at 1 and can multiply any number in the 2~9, and Ollie is doing the same, only to someone who has done more than N for this turn. 1<n<2^32-1
Find Stan's losing state, [10,18],[163,324] ... [9^n*2^ (n-1) +1,9^n*2^n] ...
Starting from 1, no matter how Stan operates, Ollie the pattern into a balanced state [9^1*2^0+1,9^1*2^1] ([10,18]) and no matter how Stan goes, Ollie the pattern into equilibrium [9^n*2^ (n-1) +1,9^n*2^n] However, the only thing Stan can do in a balanced state is to break the balance, so if n is in a state of equilibrium, Ollie will win; otherwise Stan wins.
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int n;
while (Cin>>n)
{
bool count=false;
while (n>9| | count==true)//N<=9 exit the loop
{
if (count%2==0)
n= (n%9!=0)
when the current state is a must-fail state? N/9+1:N/9; else
n= (n%2!=0)? N/2+1:N/2;
Count=!count;
}
if (n!=1)
cout<< "Stan wins." <<endl;
else
cout<< "Ollie wins." <<endl;
}
}