Pagini recente » Cod sursa (job #2561312) | Cod sursa (job #44629) | Cod sursa (job #2149320) | Istoria paginii concurs-mihai-patrascu-2013/clasament | Cod sursa (job #1710365)
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
using namespace std;
ifstream in("consecutive.in");
ofstream out("consecutive.out");
vector<pair<unsigned long long, unsigned long long>> res;
void solve(unsigned int n)
{
if (n < 3)
return;
unsigned long long nn = n * 2;
unsigned long long rad = sqrt(nn);
unsigned long long a;
unsigned long long aux;
for (unsigned int k = 2; k <= rad; k++)
{
if (nn % k == 0)
{
aux = nn / k - k + 1;
if (aux % 2 == 0)
{
a = aux / 2;
res.push_back(make_pair(a, a + k - 1));
}
}
}
}
void afis()
{
out << res.size() << "\n";
for (int i = 0; i < res.size(); i++)
out << res[i].first << " " << res[i].second<< "\n";
}
int main()
{
int t;
in >> t;
for (int i = 0; i < t; i++)
{
unsigned int n;
in >> n;
solve(n);
afis();
res.clear();
}
}