1
0
Fork 0

Add others/other/maxnum.py

This commit is contained in:
Nguyễn Gia Phong 2017-08-08 21:01:05 +07:00
parent 5cfeec0f11
commit c63bd23b97
2 changed files with 48 additions and 0 deletions

View File

@ -693,3 +693,26 @@ của một đoạn mã nguồn. Mỗi dòng chứa một câu lệnh có một
| LANG.INP | LANG.OUT |
| ----------------------------------------------------------------------- | :---------: |
| NEXT<br>JUMP 4 or 6<br>NEXT<br>JUMP 3<br>NEXT<br>JUMP 8<br>NEXT<br>NEXT | 2<br>5<br>7 |
## Tìm số
Cho hai số tự nhiên *n**p*. Tìm số *m* lớn nhất để *p<sup>m</sup>* là ước
số của *n*!.
### Dữ liệu
Gồm hai số *n**p*.
### Kết quả
Số *m* tìm được.
### Giới hạn
*n*, *p* ≤ 30000, đảm bảo *m* > 0.
### Ví dụ
| MAXNUM.INP | MAXNUM.OUT |
| :--------: | :--------: |
| 7 3 | 2 |

25
others/other/maxnum.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
PRIMES = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
139, 149, 151, 157, 163, 167, 173)
def factor(x):
d = {}
for i in PRIMES:
if not x % i:
d[i] = d.get(i, 0) + 1
x //= i
if x > 1: d[x] = 1
return d
with open('MAXNUM.INP') as f:
n, p, d = *map(int, f.readline().split()), {}
for i in range(2, n + 1):
for k, v in factor(i).items():
d[k] = d.get(k, 0) + v
with open('MAXNUM.OUT', 'w') as f:
print(min(d[k] // v for k, v in factor(p).items()), file=f)