【转】http://hi.baidu.com/sunkehappy/blog/item/0440a83e214f143470cf6ccc.html
#include <iostream>
#define DEBUG 1
using namespace std ;
int from, to ;
int stimu( )
{
int i, step = 2 ;
for( i=2,++from,--to; ; ++i ){
from += i ;
++step ;
if( from >= to )
return step ;
to -= i ;
++step ;
if( to <= from )
return step ;
}
}
int main()
{
#if DEBUG
freopen("C:\\Documents and Settings\\Administrator\\桌面\\in.txt","r",stdin) ;
freopen("C:\\Documents and Settings\\Administrator\\桌面\\out.txt","w",stdout) ;
#endif
int i, j ;
while( EOF != scanf("%d%d", &from, &to ) ){
if( to-from <= 2 ){
printf("%d\n", to-from ) ;
continue ;
}
printf("%d\n", stimu( ) ) ;
}
return 0 ;
}