ACM (UVa) : 10276


#include <stdio.h>
#include <math.h>

int x [60];
int n;
int index;

int call (int i)
{
	if ( index == n )
		return 0;

	if ( x [index] == 0 ) {
		x [index] = i;
		return 1;
	}

	int sum = x [index] + i;

	double sqr = sqrt (sum);
	sum = sqr;

	if ( sqr != sum ) {
		index ++;
		call (i);
	}

	else {
		x [index] = i;
		return 1;
	}
}

	



int main ()
{
	int t;
	int i;
	
	scanf ("%d", &t);

	while ( t-- ) {

		scanf ("%d", &n);

		for ( i = 0; i < 60; i++ )
			x [i] = 0;

		i = 1;
		index = 0;

		while ( call (i) ) {
			index = 0;
			i++;
		}

		printf("%d\n", --i);
	}

	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s