列表

详情


NC52901. 2018

描述

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

输入描述

The input consists of several test cases and is terminated by end-of-file.
Each test case contains four integers a, b, c, d.

输出描述

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

示例1

输入:

1 2 1 2018
1 2018 1 2018
1 1000000000 1 1000000000

输出:

3
6051
1485883320325200

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C(clang 3.9) 解法, 执行用时: 8ms, 内存消耗: 376K, 提交时间: 2020-08-18 16:28:57

#include <stdio.h>
#include <stdlib.h>
#include<stdio.h>
int a,b,c,d;
long long ans,x,y;
int main()
{
    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
    {
        ans=0,x=0,y=0;
        x=(b/1009-(a-1)/1009),y=(b/2018-(a-1)/2018);
        x-=y;
        printf("%lld\n",((b+1)/2-a/2-x)*(d/2018-(c-1)/2018)+(b/2-(a-1)/2-y)*(d/1009-(c-1)/1009)+y*(d-c+1)+x*(d/2-(c-1)/2));
    }
    return 0;
}

C++14(g++5.4) 解法, 执行用时: 41ms, 内存消耗: 600K, 提交时间: 2019-10-02 12:44:53

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,c,d;
    while(cin>>a>>b>>c>>d){
        ll num1=b/2018-(a-1)/2018,num2=d/2018-(c-1)/2018;
        ll ans=num2*(b-a+1)+num1*(d-c+1)-num1*num2;
        ans+=((b/2-(a-1)/2)-num1)*((d/1009-(c-1)/1009)-num2)+((b/1009-(a-1)/1009)-num1)*((d/2-(c-1)/2)-num2);
        printf("%lld\n",ans);
    }
}

C++11(clang++ 3.9) 解法, 执行用时: 27ms, 内存消耗: 484K, 提交时间: 2020-08-18 15:51:43

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,d;
int main() {
	while(cin>>a>>b>>c>>d) {
		ll num1=b/2018-(a-1)/2018,num2=d/2018-(c-1)/2018;
		ll ans=num1*(d-c+1)+num2*(b-a+1)-num1*num2;
		ans+=(b/2-(a-1)/2-num1)*(d/1009-(c-1)/1009-num2)+(b/1009-(a-1)/1009-num1)*(d/2-(c-1)/2-num2);
		cout<<ans<<endl;
	}
}

上一题