Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- def func(A, B):
- # wypełniamy count liczbą wystąpień każdego
- # elementu z tablicy B
- count = {}
- for x in B:
- if x not in count:
- count[x] = 0
- count[x] += 1
- # znajdujemy maksymalną liczbę wystąpień w tablicy B
- # wśród takich elementów, które należą do A, żeby
- # wiedzieć, o pierwszość jak dużych liczb będziemy
- # się pytać
- maxInAB = max(map(lambda x: count[x] if x in count else 0, A))
- isPrime = primes(maxInAB+1)
- C = []
- for x in A:
- if x not in count or not isPrime[count[x]]:
- C.append(x)
- return C
- # zwraca tablicę t t. że:
- # t[n] == True jeśli n jest pierwsza,
- # t[n] == False w przeciwnym wypadku
- #
- # parametr n to rozmiar tablicy do zwrócenia
- def primes(n):
- if n < 2:
- return [False] * n
- isPrime = n * [True]
- isPrime[0] = False
- isPrime[1] = False
- i = 2
- while i * i < n:
- if isPrime[i]:
- j = i
- while i * j < n:
- isPrime[i*j] = False
- j += 1
- i += 1
- return isPrime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement