Koala - 15기/기초 알고리즘 스터디

[백준/Python3] 15917번 : 노솔브 방지문제야!!

oerreo 2024. 7. 5. 20:05

https://www.acmicpc.net/problem/15917

문제

 

풀이

input = __import__('sys').stdin.readline
q = int(input())
while q:
    a = int(input())
    while a>1:
        if a % 2:
            a=0
        a//=2 
    print(a)
    q-=1

1. 빠른 입력을 받아오기 위해 'sys'의 stdin.readline으로 input을 설정한다.

2. 쿼리 a를 읽어온다.

3. a==1이면 print(a)로 1을 출력한다.

4. a>1이면 a가 홀수인지 체크해가면서 2로 나눠준다.

5. a가 홀수라면 a=0으로 초기화 한 후 print(a)로 0을 출력한다.

6. a를 2로 나누는 것을 반복하여 a==1이 되면 2의 거듭제곱이므로 print(a)로 1을 출력한다.