| Федорова Анна Дмитриевна, 527 группа RandBits 3198 | action22k RandBits 3205 | ||||
|---|---|---|---|---|---|
| f | 1 | import random | f | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| 4 | if n == 0 or n > p: | 4 | if n == 0 or n > p: | ||
| 5 | return 0 | 5 | return 0 | ||
| t | 6 | positions = random.sample(range(p), n) | t | 6 | n = random.sample(range(p), n) |
| 7 | result = 0 | 7 | ans = 0 | ||
| 8 | for pos in positions: | 8 | for i in n: | ||
| 9 | result += 1 << pos | 9 | ans |= 1 << i | ||
| 10 | return result | 10 | return ans | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||