Skip to content

Instantly share code, notes, and snippets.

@Riketta
Created September 4, 2016 16:31
Show Gist options
  • Save Riketta/c13632c88c5135c1ef0d8891ae12a09e to your computer and use it in GitHub Desktop.
Save Riketta/c13632c88c5135c1ef0d8891ae12a09e to your computer and use it in GitHub Desktop.
stepik mail.ru c/cpp course
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int main()
{
char line[256];
cin >> line;
for (int i = 0; i < 256; i++)
{
if (line[i] == 0)
break;
if (line[i] != '+' && (line[i] < '0' || line[i] > '9'))
{
cout << 0 << endl;
return 0;
}
}
long long int tn = atoll(line);
if (tn <= 0)
{
cout << 0 << endl;
return 0;
}
double index = (1 - sqrt(1 + 8.0 * tn)) / -2.0;
if (index != (long long int)index)
{
cout << 0 << endl;
return 0;
}
cout << (long long int)index << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment