码迷,mamicode.com
首页 > 其他好文 > 详细

D - Sum of Large Numbers

时间:2020-04-25 12:36:28      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:value   std   rom   base   frame   btn   ret   toggle   hose   

Time Limit: 2 sec / Memory Limit: 1024 MB

 

Score : 400 points

ps:我发现一个很有趣的问题,long long和int 一起使用时,数据过大可能会出现错误,比如下面。所以最好还是统一用long long。

Problem Statement

We have N+1 integers: 10^100 , 10^100+1, ..., 10^100+N .

We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (109+7) .

Constraints

  • 1N2×105
  • 1KN+1
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NK

Output

Print the number of possible values of the sum, modulo (10^9+7) .


Sample Input 1 Copy

Copy
3 2

Sample Output 1 Copy

Copy
10

The sum can take 1010 values, as follows:

  • (10100)+(10100+1)=2×10100+1(10100)+(10100+1)=2×10100+1
  • (10100)+(10100+2)=2×10100+2(10100)+(10100+2)=2×10100+2
  • (10100)+(10100+3)=(10100+1)+(10100+2)=2×10100+3(10100)+(10100+3)=(10100+1)+(10100+2)=2×10100+3
  • (10100+1)+(10100+3)=2×10100+4(10100+1)+(10100+3)=2×10100+4
  • (10100+2)+(10100+3)=2×10100+5(10100+2)+(10100+3)=2×10100+5
  • (10100)+(10100+1)+(10100+2)=3×10100+3(10100)+(10100+1)+(10100+2)=3×10100+3
  • (10100)+(10100+1)+(10100+3)=3×10100+4(10100)+(10100+1)+(10100+3)=3×10100+4
  • (10100)+(10100+2)+(10100+3)=3×10100+5(10100)+(10100+2)+(10100+3)=3×10100+5
  • (10100+1)+(10100+2)+(10100+3)=3×10100+6(10100+1)+(10100+2)+(10100+3)=3×10100+6
  • (10100)+(10100+1)+(10100+2)+(10100+3)=4×10100+6(10100)+(10100+1)+(10100+2)+(10100+3)=4×10100+6

Sample Input 2 Copy

Copy
200000 200001

Sample Output 2 Copy

Copy
1

We must choose all of the integers, so the sum can take just 1 value.


Sample Input 3 Copy

Copy
141421 35623

Sample Output 3 Copy

Copy
220280457
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;

int main(){
long long n,k;//若使用int n,k,答案错误
long long sum=0;
cin>>n>>k;
while(k<=n+1){
    sum+=(2*n-k+1)*k/2-k*(k-1)/2+1;
    k++;
}
sum%=mod;
cout<<sum<<endl;
return 0;
}

  

D - Sum of Large Numbers

标签:value   std   rom   base   frame   btn   ret   toggle   hose   

原文地址:https://www.cnblogs.com/asunayi/p/12772135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!