闰年规则
目前使用的格里高利历闰年规则如下:
- 公元年分非4的倍数,为平年,或
- 公元年分为4的倍数但非100的倍数,为闰年,或
- 公元年分为100的倍数但非400的倍数,为平年,或
- 公元年分为400的倍数但非3200的倍数,为闰年,或
- 公元年分为3200的倍数但非80000年的倍数,为平年,或
- 公元年分为80000的倍数为闰年。
来源:维基百科
实现代码
#include<bits/stdc++.h>
using namespace std;
bool isLeap(int n)
{
if(n%4)
return false;
if(n%100)
return true;
if(n%400)
return false;
if(n%3200)
return true;
if(n%80000)
return false;
return true;
}
int main()
{
int n;
cin>>n;
if(isLeap(n))
printf("1");
else
printf("0");
}