Created
October 23, 2019 02:03
-
-
Save surinoel/524a2c75c9b07cd5adcccc001f738bdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <set> | |
#include <queue> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
typedef long long ll; | |
struct NODE { | |
ll s, e, v; | |
NODE(ll s = 0, ll e = 0, ll v = 0) : | |
s(s), e(e), v(v) { | |
} | |
}; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
set<ll> visit; | |
queue<NODE> q; | |
vector<ll> res; | |
for (ll i = 1; i <= 1000000; ++i) { | |
if (i*(i + 1) <= 1e12) { | |
visit.insert(i*(i + 1)); | |
q.push(NODE(i, i + 1, i * (i + 1))); | |
res.push_back(i*(i + 1)); | |
} | |
} | |
while (!q.empty()) { | |
NODE now = q.front(); | |
q.pop(); | |
NODE next; | |
next = now; | |
next.s -= 1; | |
next.v *= next.s; | |
if (next.s >= 1 && visit.find(next.v) == visit.end() && next.v <= 1e12) { | |
q.push(next); | |
visit.insert(next.v); | |
res.push_back(next.v); | |
} | |
next = now; | |
next.e += 1; | |
next.v *= next.e; | |
if (next.v <= 1e12 && visit.find(next.v) == visit.end()) { | |
q.push(next); | |
visit.insert(next.v); | |
res.push_back(next.v); | |
} | |
} | |
res.push_back(0); | |
sort(res.begin(), res.end()); | |
cout << res.size() << '\n'; | |
cout << res[n] << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment