ARC002A うるう年

問題

https://atcoder.jp/contests/arc002/tasks/arc002_1

方針

ベン図を考える

ポイント

うるう年は「100の倍数ではない4の倍数」「400の倍数」の二つの集合に分けることができる。

コード

1
2
3
4
5
y = int(input())
if ((y%4==0 and y%100!=0) or y%400==0):
print ("YES")
else:
print ("NO")

その他の解法

公式の解説にあった解法。より厳しい条件から順に判定をしていくこともできる。

1
2
3
4
5
6
7
8
9
y = int(input())
if (y%400==0):
print ("YES")
elif (y%100==0):
print ("NO")
elif (y%4==0):
print ("YES")
else:
print ("NO")