NC52851. 2017
描述
输入描述
The input contains zero or more test cases and is terminated by end-of-file.
Each test case contains four integers a, b, c, d.
*
* The number of tests cases does not exceed .
输出描述
For each case, output an integer which denotes the result.
示例1
输入:
1 2017 1 2016 1 1000000000 1 1000000000
输出:
2016 991324197233775
C(clang 3.9) 解法, 执行用时: 10ms, 内存消耗: 468K, 提交时间: 2019-10-05 13:47:45
#include<stdio.h> int main() { long long a,b,c,d; while(scanf("%lld%lld%lld%lld",&a,&b,&c,&d)!=EOF){ long long count,sum1,sum2; sum1=b/2017-(a-1)/2017; sum2=d/2017-(c-1)/2017; count=sum1*(d-c+1)+sum2*(b-a+1)-sum1*sum2; printf("%lld\n",count); } return 0; }
C++14(g++5.4) 解法, 执行用时: 14ms, 内存消耗: 808K, 提交时间: 2019-10-14 14:50:27
#include <stdio.h> typedef long long ll; int main() { ll a, b, c, d, t1, t2; while(scanf("%lld %lld %lld %lld", &a, &b, &c, &d) != EOF) { t1 = b/2017 - (a-1)/2017; t2 = d/2017 - (c-1)/2017; printf("%lld\n", (b-a+1) * t2 + (d-c+1)*t1 - t1*t2); } }
C++11(clang++ 3.9) 解法, 执行用时: 11ms, 内存消耗: 500K, 提交时间: 2020-02-25 21:26:50
#include<cstdio> int main() { int a,b,c,d; while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF) { int x=b/2017-(a-1)/2017; int y=d/2017-(c-1)/2017; printf("%lld\n",1LL*x*(d-c+1)+1LL*y*(b-a+1)-1LL*x*y); } }
Python3(3.5.2) 解法, 执行用时: 69ms, 内存消耗: 3680K, 提交时间: 2019-10-05 21:04:56
import sys for line in sys.stdin: a,b,c,d=map(int,line.split()) tmp1=b//2017-(a-1)//2017 tmp2=d//2017-(c-1)//2017 print((d-c+1)*(tmp1)+(b-a+1)*tmp2-tmp1*tmp2)