Created
January 21, 2014 07:37
-
-
Save KT-Yeh/8535793 to your computer and use it in GitHub Desktop.
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 <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