๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/SWEA

[Algorithm] SWEA : 10726. ์ด์ง„์ˆ˜ ํ‘œํ˜„ by Python

by ํฌ๊ตฌ๋ฆฌ 2020. 12. 10.

๐Ÿ“Œ๋ฌธ์ œ ์„ค๋ช…

์ •์ˆ˜ N, M ์ด ์ฃผ์–ด์งˆ ๋•Œ, M์˜ ์ด์ง„์ˆ˜ ํ‘œํ˜„์˜ ๋งˆ์ง€๋ง‰ N ๋น„ํŠธ๊ฐ€ ๋ชจ๋‘ 1๋กœ ์ผœ์ ธ ์žˆ๋Š”์ง€ ์•„๋‹Œ์ง€๋ฅผ ํŒ๋ณ„ํ•˜์—ฌ ์ถœ๋ ฅํ•˜๋ผ.

๐Ÿ’ก ๋ฌธ์ œ ํ’€์ด

๋น„ํŠธ๊ฐ€ ์ผœ์ ธ์žˆ๋‹ค.(= ๋‚˜๋จธ์ง€๊ฐ€1์ด๋‹ค.)๋กœ ์ ‘๊ทผํ•˜์—ฌ ํ’€์ดํ•˜์˜€๋‹ค.

N๋งŒํผ ๋ฐ˜๋ณตํ•˜์—ฌ M์„ 2๋กœ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ ๊ณ„์†ํ•ด์„œ 1์ด๋˜๋Š” ํ™€์ˆ˜๋ฉด 'ON' ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด 'OFF'๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

def check():
    global N, M
    for i in range(N):
        if not M % 2:
            return False
        M //= 2
    else:
        return True

T = int(input())
for tc in range(T):
    N, M = map(int, input().split())
    res = 'ON' if check() else 'OFF'
    print('#{} {}'.format(tc+1, res))

์‹ค์ˆ˜๋กœ M๊ฐ’์„ ์ดˆ๊ธฐํ™”ํ•˜๋Š” M //= 2 ๋ถ€๋ถ„์„ ์ƒ๋žตํ–ˆ์—ˆ๋‹ค... ์š”์ฆ˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ ์‹ค์ˆ˜๊ฐ€ ์žฆ์€๋ฐ ์ฃผ์˜ํ•˜์ž๐Ÿ˜‚!!!

๋Œ“๊ธ€