H - Delta-wave
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

A triangle field is numbered with successive integers in the way shown on the picture below. 

H - Delta-wave(三角数据)


The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller's route. 

Write the program to determine the length of the shortest route connecting cells with numbers N and M. 
 

Input

Input contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s).
 

Output

Output should contain the length of the shortest route.
 

Sample Input


6 12
 

Sample Output


3
 #include<stdio.h>
#include<math.h>
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
//if(a==0||b==0)
//break;
int left1,left2,right1,right2,len1,len2,sum; 
len1=ceil(sqrt(a));
len2=ceil(sqrt(b));
left1=(a-(len1-1)*(len1-1)-1)/2+1;
left2=(b-(len2-1)*(len2-1)-1)/2+1;
right1=(len1*len1-a)/2+1;
right2=(len2*len2-b)/2+1;
sum=fabs(len2-len1)+fabs(left2-left1)+fabs(right2-right1);
printf("%d\n",sum);
}
return 0;
 } 

相关文章: