2018ACM-CCPC湖南湘潭邀请赛 2018 容斥原理

2018

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Given a,b,c,d, find out the number of pairs of integers (x,y) where axb,cyd and xy is a multiple of 2018.
 

Input
The input consists of several test cases and is terminated by end-of-file.

Each test case contains four integers a,b,c,d.
 

Output
For each test case, print an integer which denotes the result.

## Constraint

* 1ab109,1cd109
* The number of tests cases does not exceed 104.
 

Sample Input
 
   
1 2 1 20181 2018 1 20181 1000000000 1 1000000000
Sample Output
 
   
360511485883320325200

//给你a、b、c、d,其中x属于a-b,y属于c-d,问你有几种x,y的可能
//容斥原理
//1、x是偶数也是1009的倍数,y可以是所有数;2、x是偶数但不是1009的倍数,y是1009的倍数
//3、x是奇数也是1009的倍数,y是偶数;      3、x是奇数但不是1009的倍数,y是2018的倍数

#include 
#define ll long long
using namespace std;
int main()
{
    ll a,b,c,d;
    while(cin>>a>>b>>c>>d)
    {
        ll s1=b-a+1;
        ll s2=d-c+1;
        ll s1_o=b/2-(a-1)/2;
        ll s1_1009=b/1009-(a-1)/1009;
        ll x1,x2,x3,x4;

        x1=(b/2018-(a-1)/2018)*s2;
        x2=(s1_o-(b/2018-(a-1)/2018))*(d/1009-(c-1)/1009);
        x3=(s1_1009-(b/2018-(a-1)/2018))*(d/2-(c-1)/2);
        x4=((s1-s1_o)-(s1_1009-(b/2018-(a-1)/2018)))*(d/2018-(c-1)/2018);
        printf("%lld\n",x1+x2+x3+x4);
    }
    return 0;
}

你可能感兴趣的:(2018ACM-CCPC湖南湘潭邀请赛 2018 容斥原理)