Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created January 21, 2014 07:37
Show Gist options
  • Save KT-Yeh/8535793 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8535793 to your computer and use it in GitHub Desktop.
#include <cstdio>
using namespace std;
int main()
{
// freopen ("input.txt","rt",stdin);
int N;
int x,y;
scanf("%d",&N);
while (N--){
scanf("%d%d",&x,&y);
int steps = 0, length;
long long int sum = 0, distance = y-x;
for (length=0;;) {
length++;
if (sum + 2*length > distance) break;
sum += 2*length;
steps += 2;
}
if (sum + length < distance) steps += 2;
else if (sum != distance) steps += 1;
printf("%d\n",steps);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment