Advertisement
nq1s788

19 можно ход только делителем

Oct 16th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from functools import lru_cache
  2.  
  3.  
  4. def moves(h):
  5.     move = []
  6.     for k in range(2, h + 1):
  7.         if h % k == 0:
  8.             move.append(h + h // k)
  9.     return move
  10.  
  11.  
  12. @lru_cache(None)
  13. def game(h):
  14.     if h >= 41:
  15.         return 'win'
  16.     elif any(game(m) == 'win' for m in moves(h)):
  17.         return'p1'
  18.     elif all(game(m) == 'p1' for m in moves(h)):
  19.         return'v1'
  20.     elif any(game(m) == 'v1' for m in moves(h)):
  21.         return'p2'
  22.     elif all(game(m) in ['p1', 'p2'] for m in moves(h)):
  23.         return'v2'
  24.  
  25.  
  26. def p19(h):
  27.     return any(game(m) == 'p1' for m in moves(h))
  28.  
  29.  
  30. print(len([s for s in range(1, 41) if p19(s)]))
  31. print([s for s in range(1, 150) if (s % 3 != 0) and game(s) == 'p2'])
  32. print([s for s in range(1, 150) if (s % 3 != 0) and game(s) == 'v2'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement