Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / Tasks and Solutions / 09. SumFromKtoN.cpp
blob: aea318aa26e96a0c09315e7a50427700c51e129d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> k >> n;

	int sum = 0;
	for (int i = k; i <= n; i++)
		sum += i;

	cout << sum << endl;

	//or use the formula

	cout << (n*(n + 1)) / 2 - ((k - 1)*k) / 2 << endl;
}