1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#include <iostream> #include <math.h> using namespace std; //long long diff[10001]; long long int m,n,d; int main() { int t; cin>>t; while(t--) { cin>>m>>n; d= m-n; if(d<0) d=d*(-1); if(d==0) { cout<<0<<"\n"; continue; } if(d==1) { cout<<1<<"\n"; continue; } if(d==2) { cout<<2<<"\n"; continue; } if(d==3) { cout<<3<<"\n"; continue; } long long int r= sqrt(d); if(r<0) r*=-1; if(d==r*r) { cout<<2*r-1<<"\n"; continue; } long long int x=(r+1)*(r+1)-r*r; if(d<=(r*r)+x/2) cout<<2*r<<"\n"; else cout<<2*r+1<<"\n"; } return 0; } |