UVA – 11614 – Etruscan Warriors Never Play Chess

  • Problem StatementUVA – 11614 – Etruscan Warriors Never Play Chess
  • Type : Simple Math
  • Solution : write the equation of the arithmetic sequence and solve it for n. Sn = n*(a1 + an)/2;
  • Gochas : The input is pretty large (10^18) so use double instead.

#include <iostream>
#include <math.h>
using namespace std;

int main() {
	double N, s;
	cin >> N;
	while(N-- && (cin >> s))
		cout << long((sqrt(1+8*s)-1)/2)<< endl;
	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

%d bloggers like this: