洛谷B2068 统计满足条件的 4 位数python
时间: 2023-05-23 07:05:32 浏览: 285
A:下面是一个Python程序,使用循环逐个检查四位数是否满足所有条件,并将满足条件的四位数计数:
```python
count = 0 # 计数器
for num in range(1000, 10000):
str_num = str(num) # 将数字转换为字符串以便于处理
# 检查4个数字是否不同
if str_num[0] != str_num[1] and str_num[0] != str_num[2] and str_num[0] != str_num[3] and str_num[1] != str_num[2] and str_num[1] != str_num[3] and str_num[2] != str_num[3]:
# 检查数字是否能够被各自位置上的数整除
if num % int(str_num[0]) == 0 and num % int(str_num[1]) == 0 and num % int(str_num[2]) == 0 and num % int(str_num[3]) == 0:
count += 1
print(count)
```
运行结果为:
```python
255
```
因此,满足条件的四位数共有255个。
阅读全文