Created
September 4, 2016 16:31
-
-
Save Riketta/c13632c88c5135c1ef0d8891ae12a09e to your computer and use it in GitHub Desktop.
stepik mail.ru c/cpp course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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