您的位置:首页 > 编程语言 > Python开发

Python--ZOJ1350

2015-03-26 21:31 417 查看

Python--ZOJ1350

这题比较简单,假设是对一个长为N的序列进行操作,每一次遍历按照一定的规则(当前序列号 除以 当前遍历的次数 余数为0)改变其状态,求其最后的为True(牢房打开)的有多少。不在累赘,代码如下:

#-*- coding:utf-8 -*-
#2015-03-26

state = False

N = input()
while N:
n = input()
cell = [False for i in range(n+1)]
for i in range(1,n+1):
for j in range(1,n+1):
if j%i==0:
if cell[j] == False:
cell[j] = True
else:
cell[j] = False

count = 0
for i in cell[1:]:
if i:
count += 1

print count
N -= 1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: