-
Notifications
You must be signed in to change notification settings - Fork 0
/
847.cpp
49 lines (36 loc) · 790 Bytes
/
847.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <algorithm>
using namespace std;
int n;
map <int ,bool> memo;
bool best( int p ) {
if ( p >= n ) {
memo[ p ] = false;
return ( false );
}
if ( memo.find( p ) != memo.end() ) {
return ( memo[ p ] );
}
bool Best = false;
for ( int i = 2; i <= 9; ++i ) {
if ( !best( p * i ) ) {
return ( memo[ p ] = true );
}
}
return ( memo[ p ] = Best );
}
int main( ) {
while ( scanf( "%d", &n ) != EOF ) {
memo.clear();
if ( best( 1 ) ) {
printf( "Stan wins.\n" );
}else {
printf( "Ollie wins.\n" );
}
}
return 0;
}