#include <bits/stdc++.h>
#define int long long
void solve() {
int k;
std::cin >> k;
int h = 0;
std::vector<std::pair<int,int>> ans;
ans.push_back({1, 0});
// h * (h - 1) / 2
int node = 2;
int last = 0;
for(int i = 1; i; i++) {
if(i * (i - 1) / 2 <= k) {
last = i;
}
else {
break;
}
}
const int N = 5e5;
std::vector<int> dep(N);
dep[1] = 1;
int prv = 1;
for(int i = 2; i <= last; i++) {
dep[i] = node;
ans.push_back({node, prv});
prv = node;
node++;
}
k -= last * (last - 1) / 2;
while(k > 0) {
int lst = 0;
for(int i = 1; i; i++) {
if(i * (i - 1) / 2 <= k) {
lst = i;
}
else {
break;
}
}
ans.push_back({node++, dep[lst]});
k -= lst * (lst - 1) / 2;
}
std::cout << ans.size() << "\n";
for(auto [x, y] : ans) {
x -= 1;
y -= 1;
std::cout << x << " " << y << "\n";
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
//std::cin >> t;
while (t--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |