Cod sursa(job #1709181)

Utilizator ubb_912codersUBB Badila Bereczki Bodea ubb_912coders Data 28 mai 2016 11:10:34
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.55 kb
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

struct S
{
	int a, b;
};
vector<S> v1;
int t, i, q, j;
bool comp(S a, S b)
{
	return (a.b-a.a<b.b-b.a);
}

int main()
{
	ifstream f("consecutive.in");
	ofstream g("consecutive.out");
	f>>t;
	for(i=1; i<=t; i++)
	{
		v1.clear();
		//v2.clear();
		f>>q;
		int p=sqrt(q);
		for(j=2; j<=p; j++)
		{
			if(j%2==0)
			{
				if((double)q/(double)j - (int)q/j==0.5)
				{
					int st=q/j-(j/2)+1;
					int dr=q/j+(j/2);
					if(st>=0 && dr>=0)
					{
					S A;
							A.a=st;
							A.b=dr;
						v1.push_back(A);
					}
				}
			}
			if(j%2==1 && q%j==0)
			{
				int st=q/j-j/2;
				int dr=q/j+j/2;
				if(st>=0 && dr>=0)
				{
				S A;
							A.a=st;
							A.b=dr;
						v1.push_back(A);
				}
			}
			if(q%j==0)
			{
				int b=q/j;
				if(b==j)
					continue;
				if(b%2==0)
				{
					if((double)q/(double)b - (int)q/b==0.5)
					{
						int st=q/b-(b/2)+1;
						int dr=q/b+(b/2);
						if(st>=0 && dr>=0)
						{
							S A;
							A.a=st;
							A.b=dr;
						v1.push_back(A);
						}
					}
				}
				if(b%2==1 && q%b==0)
				{
					int st=q/b-b/2;
					int dr=q/b+b/2;
					if(st>=0 && dr>=0)
					{
					S A;
							A.a=st;
							A.b=dr;
						v1.push_back(A);
					}
				}
			}
		}
		sort(v1.begin(), v1.end(), comp);
		g<<v1.size()<<"\n";
		for(j=0; j<v1.size(); j++)
		{
			if(v1[j].a==0)
				g<<1<<" "<<v1[j].b<<"\n";
			else
			{
			g<<v1[j].a<<" "<<v1[j].b<<"\n";
			}
		}
	}
	
}