8000 Update 1292.cpp · w10gd/basic-algo-lecture@19b288a · GitHub
[go: up one dir, main page]

Skip to content

Commit 19b288a

Browse files
author
SciEm
committed
Update 1292.cpp
1 parent 816221b commit 19b288a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

0x12/solutions/1292.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : SciEm
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/2fe6deab624e4c83b409ab234ee8aa48
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
int func(int n) {
8+
int i = 1, sum = 0;
9+
while (n > i) sum += i * i, n -= i++;
10+
return sum + i * n;
11+
}
12+
13+
int main() {
814
ios::sync_with_stdio(0);
915
cin.tie(0);
10-
11-
}
16+
17+
int a, b;
18+
cin >> a >> b;
19+
cout << func(b) - func(a - 1);
20+
}
21+
/*
22+
수열을 (1) (2 2) (3 3 3) ... 과 같이 묶으면 i 번째 군의 합은 i * i임을 이용했다.
23+
*/

0 commit comments

Comments
 (0)
0