Daily AtCoder # 42 in Python

Introduction

Last time Solve yesterday's ABC-D.

#42 Problem

** Thoughts ** Even after reading the explanation, it wasn't refreshing, so I implemented it with reference to Kenchon's article. The important thing in thinking about this issue is to be aware of the intent that $ 10 ^ {100} $ is written. As I wrote in the commentary article, the sum of the selected numbers will not be duplicated when different numbers are selected due to the presence of $ 10 ^ {100} $. Also, the sum is a continuous integer. From the above, it can be considered as a problem of calculating the sum of the numbers selected from k to N + 1 from {0,1, ... N + 1}. The number of sums can be written as (the largest integer that can be made from $ i-the smallest integer that can be made from i + 1 $, $ k \ leq i \ leq N + 1 $). The minimum sum of the $ i $ th is $ \ frac {i (i-1)} {2} $, and the sum of the maximum nth to kth is $ \ frac {i (2N-i + 1)} { 2} $. When these are implemented,

n, k = map(int,input().split())

ans = 0
for i in range(k,n+2):
    minmin = (i*(i-1))//2 #Variable name is terrible
    maxmax = ((2*n-i+1)*i)//2
    ans += maxmax - minmin + 1

print(ans%(10**9+7))

Summary

This contest was C: Easy, D: A little easy, E: What? So I thought I had to solve about D. See you again, good night

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python