Pagini recente » Cod sursa (job #2143998) | Cod sursa (job #2575772) | Cod sursa (job #732347) | Cod sursa (job #2226815) | Cod sursa (job #1709796)
#include <fstream>
#include <algorithm>
using namespace std;
int64_t N;
vector<pair<int64_t, int64_t>> d;
vector<pair<int64_t, int64_t>> e;
bool Check(int64_t x, int64_t y) {
return ((x < y) && (y * (y + 1) / 2 - x * (x - 1) / 2 == N / 2));
}
int main() {
ifstream f("consecutive.in");
ofstream g("consecutive.out");
int T;
for(f >> T; T > 0; T--) {
d.clear();
e.clear();
f >> N;
N <<= 1;
for(int i = 2; 1LL * i * i <= N; i++) {
if(N % i == 0) {
int64_t Z = N / i;
d.push_back(make_pair(i, Z));
}
}
for(vector<pair<int64_t, int64_t>> :: iterator it = d.begin(); it != d.end(); it++) {
int64_t y = (it->first + it->second - 1) / 2;
int64_t x = it->second - y;
if(x > y) swap(x, y);
e.push_back(make_pair(x, y));
}
sort(e.begin(), e.end(), [](pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
return a.second - a.first < b.second - b.first; });
int ans = 0;
for(vector<pair<int64_t, int64_t>> :: iterator it = e.begin(); it != e.end(); it++) {
if(Check(it->first, it->second))
++ans;
}
g << ans << '\n';
for(vector<pair<int64_t, int64_t>> :: iterator it = e.begin(); it != e.end(); it++) {
if(Check(it->first, it->second)) {
g << it->first << ' ' << it->second << '\n';
}
}
}
return 0;
}