[백준] 1476번 (python 파이썬) 날짜계산

2021. 3. 23. 19:13발돋움/알고리즘

728x90
반응형

 

 

e, s, m = map(int, input().split())
s = time.time()
year = 1
while True:
    if (year % 15 == e) & (year % 28 == s) & (year % 19 == m):
        print(year)
        break
    year += 1

 

처음에는 위와 같은 코드로 정답이 잘 나오길래 제출을 했는데 시간초과가 났다.

728x90

 

e, s, m = map(int, input().split())

e -= 1
s -= 1
m -= 1
year = 0
while True:
    if year % 15 == e and year % 28 == s and year % 19 == m:
        print(year + 1)
        break
    year += 1

 

위와 같이 바꾸니 정답이 맞았다. year와 각 날짜가 1 차이 나는 것 빼고는 똑같은데 왜 그런지 모르겠다.

728x90
반응형