Advertisement
NikolayChukanov

homework16052022

May 16th, 2022
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #1
  2. def f(x, A, P, Q):
  3.     return ((x in P) <= (x in A)) or ((x not in A) <= (x not in Q))
  4.  
  5.  
  6. #P = [1, 3, 4, 9, 11, 13, 15, 17, 19, 21]
  7. #Q = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
  8. P = [1, 3, 4, 9, 11, 13, 15, 17, 19, 21]
  9. Q = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
  10. A = set()
  11. for x in [i for i in range (0, 600)]:
  12.     if not f(x, A, P, Q):
  13.         A.add(x)
  14. print(len(A))
  15.  
  16. #2
  17. def f(n):
  18.     if n == 1:
  19.         return 1
  20.     if n > 1 and n % 2 == 1:
  21.         return f(n-2) + n
  22.     if n % 2 == 0:
  23.         return n * f(n-1)
  24.    
  25. print(f(40))
  26.  
  27. #3
  28. def f(x, last):
  29.     if x > last or x == 22:
  30.         return 0
  31.     elif x == last:
  32.         return 1
  33.     return f(x + 1, last) + f(x * 2, last) + f(x * 3, last)
  34. print(f(2, 50))
  35.  
  36. #4
  37. s = '7' * 40 + '9' * 40 + '4' * 50
  38.  
  39. while '49' in s or '97' in s or '47' in s:
  40.     if '47' in s:
  41.         s = s.replace('47', '74', 1)
  42.     if '97' in s:
  43.         s = s.replace('97', '79', 1)
  44.     if '49' in s:
  45.         s = s.replace('49', '94' , 1)
  46.  
  47. print(s)
  48. print(794)
  49.  
  50. #5
  51. with open('28140.txt', 'r') as f:
  52.     s, n = map(int, f.readline().split())
  53.     lst = [int(line) for line in f]
  54.     lst.sort()
  55.    
  56.     t = s
  57.     index = 0
  58.     while t - lst[index] >= 0:
  59.         #print(t, index)
  60.         t -= lst[index]
  61.         index += 1
  62.         #print(t)
  63.    
  64.     print(index, lst[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement