Python--ZOJ1350

来源:互联网 发布:淘宝怎么申请换货 编辑:程序博客网 时间:2024/06/14 10:24

Python--ZOJ1350

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

#-*- coding:utf-8 -*-#2015-03-26state = FalseN = 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


0 0
原创粉丝点击