<-E 1025> Divisor Game
// Method 1
class Solution {
public:
bool divisorGame(int N) {
if(N % 2 == 0)
return true;
else
return false;
}
};
// Method 2
class Solution {
public:
int dp[1001] ;
int help(int N) {
if(N == 1)
return 0;
if(dp[N] != -1)
return dp[N];
else {
for(int i = 1; i * i <= N; i++) {
if(N % i == 0) {
if(help(N - i) == 0)
return dp[N] = 1;
if((i != 1) && help(N - (N /i)) == 0)
return dp[N] = 1;
}
}
}
return dp[N] = 0;
}
bool divisorGame(int N) {
memset(dp, -1, sizeof(dp));
return help(N);
}
};