小明在玩爬塔游戏,他从第一层开始。
他的目标是爬到第n层的第r个房间,他目前位于第1第l个房间,接下来他要一路披荆斩棘到达目标房间。
每个房间都会有收益,对于第i层第j个房间收益为i。
小明从起点出发,先扫荡完第一层第l个房间到第r个房间,再从第一层第r个房间通过神秘的阶梯到达第二楼第l个房间,再扫荡完第二层第l∼r个房间,依次类推,直到到达第n层第r房间。
小明想知道自己的收益。
第一行三个整数n,l,r。
一行一个整数,表示答案
2 3 4
6
第一层收益为1,1;第二层收益为2,2.
一共收益为1+1+2+2=6
对于30%的数据,1≤n,l,r≤100。
对于60%的数据,1≤n,l,r≤10^3。
对于80%的数据,n≤10^6。
对于100%的数据,1≤n≤10^9,1≤l≤r≤10^6。
input: 2 96 100
output:
15
input: 72 13 38
output: 68328
input: 57 73 85
output: 21489
input: 449 331 564
output: 23639850
input: 199 74 540
output: 9293300
input: 913 453 540
output: 36717208
input: 780104 8507 877461
output: 264406944266544300
input: 617537 3781 385237
output: 72734802484945521
input: 539897 2054 171112
output: 24639445672416927
input: 707423041 11802 582357
output: 142766621864837896550716
最后一个测试点没人对,那就附上能对九个的代码,请大佬帮个忙把第十个也AC吧。。。
Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,l,r;
scanf("%lld%lld%lld",&n,&l,&r);
ll m=r-l+1;
ll ans=(n+1)*n/2*m;
printf("%lld\n",ans);
return 0;
}