안선생의 개발 블로그

C++ 1789 수들의 합 본문

백준

C++ 1789 수들의 합

안선생 2023. 2. 11. 19:31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
 
    long s =0;
    long n; cin >> n;
    int i = 1;
    while (1)
    {
        s += i++;
        if (s > n)
        {
            i--;
            break;
        }
    }
    cout << i-1;
    return 0;
}
 
 
cs

 

https://www.acmicpc.net/problem/1789

 

1789번: 수들의 합

첫째 줄에 자연수 S(1 ≤ S ≤ 4,294,967,295)가 주어진다.

www.acmicpc.net

 

'백준' 카테고리의 다른 글

C++ 백준 2846 5와 6의 차이  (0) 2023.02.11
C++ 1026 보물  (0) 2023.02.11
C++ 4796 캠핑  (0) 2023.02.11
C++ 10610 30  (0) 2023.02.11
C++ 1439 뒤집기  (0) 2023.02.11