Input : First line of input contains an integer t denoting the no of test cases. Then T test cases follow. Each test case contains an integer N.
Output:
For each test case in a new line print the n space separated integers either (1 or 0) depending on the status of the ith door where 1 denotes the door is open and a 0 denotes door is closed.
Constraints:
1 <= T <= 100
1 <= N <= 1000
Example:
Input:
2
3
5
Output:
1 0 0
1 0 0 1 0
Output:
For each test case in a new line print the n space separated integers either (1 or 0) depending on the status of the ith door where 1 denotes the door is open and a 0 denotes door is closed.
Constraints:
1 <= T <= 100
1 <= N <= 1000
Example:
Input:
2
3
5
Output:
1 0 0
1 0 0 1 0
Solution:
def check(n):
keys=[]
for i in range(1,n+1):
keys.append(i)
l={}
for k in keys:
l[k]=0
for person in range(1,n+1):
for door in range(1,n+1):
if(door%person==0):
if(l[door]==0):
l[door]=1
elif(l[door]==1):
l[door]=0
for v in l.values():
print(v,end=" ")
t=int(input())
for i in range(t):
n=int(input())
# print(n)
check(n)
print()
0 Comments