python-algorithm
[백준] 15917
무적김두칠
2021. 1. 4. 11:33
1
2
3
4
5
6
7
8
9
10
|
import sys
import math
def log2(x):
return (math.log10(x) / math.log10(2) )
def isPower2(n):
if (math.ceil(log2(n))== math.floor(log2(n))) : return 1
else: return 0
for _ in range(int(sys.stdin.readline())):
a=int(sys.stdin.readline())
print( isPower2(a) )
|
cs |
본 문에서 주어진 힌트와 유사한 방법 이겠네요
엄청나게 큰 수나 엄청나게 작은 수를 다루기 위해 지수와 로그 개념이 도입됩니다.
그리고 로그의 성질을 이용해서 ex) log8 == 3 * log2
문제를 해결했습니다.
반응형