https://www.acmicpc.net/problem/1484
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define ll long long
static const auto fastio = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
};
ll n, cnt;
int main() {
cin >> n;
ll s[50001];
for (ll i = 1; i < 50001; i++) s[i] = i * i;
for (ll i = 1; i < 50001; i++) {
auto iter1 = lower_bound(s + 1, s + i, i * i - n);
auto iter2 = upper_bound(s + 1, s + i, i * i - n);
if (*iter1 != *iter2) {
cout << i << "\n"; cnt++;
}
}
cout << (cnt == 0 ? "-1" : "");
return 0;
}
|
cs |
간단한 이분탐색 문제입니다.
lower_bound와 upper_bound의 특성을 활용하여 풀었습니다.
'설명없음' 카테고리의 다른 글
백준 16236: 아기 상어 [C언어], 삼성 코딩 테스트 (0) | 2022.06.13 |
---|---|
백준 14921: 용액 합성하기 [C/C++] (0) | 2022.06.08 |
백준 1940: 주몽 [C/C++], 투 포인터 (0) | 2022.06.08 |
백준 20192: 순서 섞기 [C언어] (0) | 2022.06.03 |
백준 11053: 가장 긴 증가하는 부분 수열, 파이썬 (0) | 2022.06.03 |