Pagini recente » Cod sursa (job #969161) | Cod sursa (job #2380051) | Cod sursa (job #12316) | Cod sursa (job #762657) | Cod sursa (job #1708939)
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
ifstream f("consecutive.in");
ofstream g("consecutive.out");
int t,d,a,n,i;
vector<pair<int,int> >sol;
bool cmp(pair<int,int>a, pair<int,int>b)
{
return (a.second - a.first) < (b.second-b.first);
}
int main()
{
f >> t;
for(; t; --t)
{
f >> n;
n *= 2;
for(d = 2; d * d <= n; ++d)
if(n % d == 0)
{
a = (n / d) - d + 1;
if(a % 2 == 0 && a > 0)
{
a /= 2;
sol.push_back(make_pair(a, a + d - 1));
}
int k = n / d;
a = (n / k) - k + 1;
if(a % 2 || a <= 0)
continue;
a /= 2;
sol.push_back(make_pair(a, a + k - 1));
}
g << sol.size() << '\n';
sort(sol.begin(), sol.end(), cmp);
for(i = 0; i < sol.size(); ++i)
g << sol[i].first << ' ' << sol[i].second << '\n';
sol.clear();
}
return 0;
}