Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1
- def f(x, A, P, Q):
- return ((x in P) <= (x in A)) or ((x not in A) <= (x not in Q))
- #P = [1, 3, 4, 9, 11, 13, 15, 17, 19, 21]
- #Q = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
- P = [1, 3, 4, 9, 11, 13, 15, 17, 19, 21]
- Q = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
- A = set()
- for x in [i for i in range (0, 600)]:
- if not f(x, A, P, Q):
- A.add(x)
- print(len(A))
- #2
- def f(n):
- if n == 1:
- return 1
- if n > 1 and n % 2 == 1:
- return f(n-2) + n
- if n % 2 == 0:
- return n * f(n-1)
- print(f(40))
- #3
- def f(x, last):
- if x > last or x == 22:
- return 0
- elif x == last:
- return 1
- return f(x + 1, last) + f(x * 2, last) + f(x * 3, last)
- print(f(2, 50))
- #4
- s = '7' * 40 + '9' * 40 + '4' * 50
- while '49' in s or '97' in s or '47' in s:
- if '47' in s:
- s = s.replace('47', '74', 1)
- if '97' in s:
- s = s.replace('97', '79', 1)
- if '49' in s:
- s = s.replace('49', '94' , 1)
- print(s)
- print(794)
- #5
- with open('28140.txt', 'r') as f:
- s, n = map(int, f.readline().split())
- lst = [int(line) for line in f]
- lst.sort()
- t = s
- index = 0
- while t - lst[index] >= 0:
- #print(t, index)
- t -= lst[index]
- index += 1
- #print(t)
- print(index, lst[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement