Skip to content

Instantly share code, notes, and snippets.

@OmarJH
Created September 26, 2015 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmarJH/3d9a581917eb33f2b129 to your computer and use it in GitHub Desktop.
Save OmarJH/3d9a581917eb33f2b129 to your computer and use it in GitHub Desktop.
Syrian Collegiate Programming Contest
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long double sec(long double a, long double b, long double c)
{
long double del = b*b - 4 * a *c;
long double x1 = (-sqrt(del) - b) / 2*a;
long double x2 = (sqrt(del) - b) / 2*a;
if (x1 > 0 && x1 < 0)
return x1;
if (x2>0 && x1 < 0)
return x2;
return x2;
}
int main()
{
int c = 1;
long long m, u, d,t;
int n;
cin >> t;
while (t--)
{
cin >> n>> m;
m--;
long long j =floor (sec(1, 1, -2 * m));
d = m - (j*(j + 1)) / 2;
cout << "Case " << c++ << ": ";
cout << j << " " << d << endl;
}
//cin >> t;
}
@OmarJH
Copy link
Author

OmarJH commented Sep 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment