编程环境:C++
题目:
代码:
考虑到题目给的范围是[1,100000000],所以我用了long double。
结果:
为什么有个超时了?
编程环境:C++
题目:
为什么有个超时了?
4的倍数的年数减去100的倍数的年加上400倍数的年即为闰年个数
#include<iostream>
using namespace std;
int main()
{
int count4,count100,count400;
int a, b;
cin >> a >> b;
count4 = b/4-(a-1)/4; //4的倍数的年
count100 = b/100-(a-1)/100; //100倍数的年
count400 = b/400-(a-1)/400; //400倍数的年
cout << count4 - count100 + count400;
}