Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created February 9, 2014 01:18
Show Gist options
  • Save KT-Yeh/8892785 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8892785 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int Case, k;
scanf("%d",&Case);
while (Case--){
scanf("%d",&k);
k = abs(k);
int n = 0;
int sum = 0;
while (sum < k) sum += (++n);
if (k % 2)
while (sum % 2 != 1) sum += (++n);
else
while (sum % 2 != 0) sum += (++n);
if (k == 0) printf("3\n");
else printf("%d\n",n);
if (Case) printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment