-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwo_pointer_diet.cpp
More file actions
49 lines (40 loc) · 1 KB
/
Two_pointer_diet.cpp
File metadata and controls
49 lines (40 loc) · 1 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
// F_I 사용하면 cin 과 scanf 를 섞어서 쓰면 안된다!
#define F_I ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
ll Min(ll a, ll b) { return (a < b) ? a : b; }
ll Max(ll a, ll b) { return (a < b) ? b : a; }
ll gcd(ll m, ll n) { if (n == 0) return m; return gcd(n, m % n); } //최대공약수
ll lcm(ll m, ll n) { return m * n / gcd(m, n); } //최소공배수
int main()
{
F_I;
// [백준] 1484번 : 다이어트 (투 포인터)
vector<int> ans; //ans에 가능한 현재 몸무게 넣어준다. ans가 empty 면 -1 출력!
int G;
cin >> G;
int s = 1, e = 1;
while (e >= s && e <= G && s <= G)
{
if (e * e - s * s > G)
s += 1;
if (e * e - s * s < G)
e += 1;
if (e * e - s * s == G)
{
ans.push_back(e);
e += 1;
}
}
if (ans.empty())
cout << -1 << '\n';
else
{
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << '\n';
}
return 0;
}