https://www.acmicpc.net/problem/1292
- Python
a, b = map(int, input().split())
numbers = []
Sum = 0
for i in range(1,1001):
for j in range(i) :
numbers.append(i)
print(sum(numbers[a-1:b]))
- C++
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <charconv>
using namespace std;
int main() {
int a, b, Sum = 0;
vector<int> v;
cin >> a >> b;
for (int i = 1; i <= 1001; i++) {
for (int j = 1; j <= i; j++) {
v.push_back(i);
}
}
for (int i = a; i <= b; i++) {
Sum += v[i-1];
}
cout << Sum;
}
'자기개발👨💻 > 코딩 알고리즘' 카테고리의 다른 글
[C++] 백준 2309 일곱 난쟁이 (0) | 2022.02.27 |
---|---|
[python] 프로그래머스 실패율 (0) | 2022.02.10 |
[C++] 백준 5054 주차의 신 (0) | 2022.02.03 |
[python, C++] 백준 2953 나는 요리사다 (0) | 2022.02.03 |
[python, C++] 백준 2711 오타맨 고창영 (0) | 2022.02.03 |
[python, C++] 백준 2592 대표값 (0) | 2022.01.30 |