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

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

题目传送门

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

#include
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;
} 

你可能感兴趣的:(递推,找规律)