e题的一个超简单的代码


思路:把区间每一天看作365天,再加上区间里闰年数即可

#include<iostream>
using namespace std;

bool solve(int x)
{
    if(x%4==0&&x%100!=0||x%400==0)return true;
    return false;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        
        long long res=0;
        
        int c=a/4,d=b/4,e=a/100,f=b/100,g=a/400,h=b/400;
        
        if(a%4==0)c--;
        if(a%100==0)e--;
        if(a%400==0)g--;
        
        res+=((d-c)*1ll*366+(b-a+1-(d-c))*1ll*365);
        res-=(f-e);
        res+=(h-g);
        
        cout<<res<<'\n';
    }
    return 0;
}