欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AtCoder Beginner Contest 163 D - Sum of Large Numbers(递推&找规律)

程序员文章站 2022-07-15 16:18:49
...

AtCoder Beginner Contest 163 D - Sum of Large Numbers(递推&找规律)

题目传送门

思路:
AtCoder Beginner Contest 163 D - Sum of Large Numbers(递推&找规律)
AC代码:

#include<bits/stdc++.h>
using namespace std;
const double pi=atan(1.0)*4;
typedef long long ll;
const ll mod=1e9+7; 
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	ll ans=0;
	for(int i=k;i<=n+1;i++){
		ans=(ans+(ll)i*(2*n-i+1)/2-(ll)i*(i-1)/2+1)%mod;
	} 
	printf("%lld\n",ans);
	return 0;
} 
相关标签: 递推 找规律