Pagini recente » Cod sursa (job #1928413) | Cod sursa (job #811559) | Cod sursa (job #2629938) | Cod sursa (job #3221218) | Cod sursa (job #1709562)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("consecutive.in");
ofstream out("consecutive.out");
bool isPowerOfTwo(long long n)
{
if ((n & (n - 1)) == 0)
return 1;
return 0;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y)
{
if ((y.second - y.first) >= (x.second - x.first))
return true;
return false;
}
int main()
{
int T; in >> T;
for (int t = 0; t < T; t++)
{
int N; in >> N;
vector<pair<int, int>> sol;
if (isPowerOfTwo(N) || N == 1)
{
out << 0 << '\n';
continue;
}
sol.push_back(make_pair(N / 2, N / 2 + 1));
for (int q = 3; q <= N / 3; q += 2)
{
if (N % q != 0)
{
continue;
}
int r = N / q;
int left = r - q / 2;
int right = r + q / 2;
if (left < 1)
{
continue;
}
sol.push_back(make_pair(left, right));
}
sort(sol.begin(), sol.end(), cmp);
out << sol.size() << '\n';
for (int i = 0; i < sol.size(); i++)
{
out << sol[i].first << ' ' << sol[i].second << '\n';
}
}
return 0;
}