maxim_shlyahtin

102

Nov 25th, 2021
576
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print('Задача 19')
  2.  
  3.  
  4. def f(x, y, p):
  5.     if x + y >= 59 and p == 3:
  6.         return True
  7.     elif x + y < 59 and p == 3:
  8.         return False
  9.     return f(x + 2, y, p + 1) or f(x * 2, y, p + 1) or f(x, y + 2, p + 1) or f(x, y * 2, p + 1)
  10.  
  11.  
  12. for s in range(1, 101):
  13.     if f(5, s, 1):
  14.         print(s)
  15.         break
  16.  
  17. print('Задача 20')
  18.  
  19.  
  20. def f(x, y, p):
  21.     if x + y >= 59 and p == 4:
  22.         return True
  23.     elif x + y < 59 and p == 4:
  24.         return False
  25.     elif x + y >= 59 and p != 4:
  26.         return False
  27.     if p % 2 == 1:
  28.         return f(x + 2, y, p + 1) or f(x * 2, y, p + 1) or f(x, y + 2, p + 1) or f(x, y * 2, p + 1)
  29.     else:
  30.         return f(x + 2, y, p + 1) and f(x * 2, y, p + 1) and f(x, y + 2, p + 1) and f(x, y * 2, p + 1)
  31.  
  32.  
  33. for s in range(1, 101):
  34.     if f(5, s, 1):
  35.         print(s)
  36.         break
  37.  
  38. print('Задача 21')
  39.  
  40.  
  41. def f(x, y, p):
  42.     if x + y >= 59 and (p == 5 or p == 3):
  43.         return True
  44.     elif x + y < 59 and p == 5:
  45.         return False
  46.     elif x + y >= 59 and p != 5:
  47.         return False
  48.     if p % 2 == 0:
  49.         return f(x + 2, y, p + 1) or f(x * 2, y, p + 1) or f(x, y + 2, p + 1) or f(x, y * 2, p + 1)
  50.     else:
  51.         return f(x + 2, y, p + 1) and f(x * 2, y, p + 1) and f(x, y + 2, p + 1) and f(x, y * 2, p + 1)
  52.  
  53.  
  54. for s in range(1, 101):
  55.     if f(5, s, 1):
  56.         print(s)
RAW Paste Data