Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created November 7, 2013 13:35
Show Gist options
  • Save cocodrips/7354651 to your computer and use it in GitHub Desktop.
Save cocodrips/7354651 to your computer and use it in GitHub Desktop.
SRM575 Div2 Medium / 二人で勝負をする問題 どちらか一方の立場になって自分が勝つか負けるかmemoしてく
class TheNumberGameDivTwo:
def find(self, n):
if self.rec(n):
return 'John'
return 'Brus'
def rec(self, n, memo={}):
if n in memo:
return memo[n]
memo[n] = self.d(n)
return memo[n]
def d(self, n):
array = []
for i in xrange(2, n):
if n % i == 0:
array.append(i)
if not array:
return False
for i in array:
if not self.rec(n - i):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment