Sunday, October 23, 2016

UVA 846 - Steps

#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define LL long long
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   LL T;
   cin >> T;
   while(T--){
    LL x , y;
    cin >> x >> y;
    LL diff = abs(x-y) , start = 1 , cnt = 0;
    bool flag = false;
    while(diff > 0){
        diff-=start;
        cnt++;
        if(flag)start++;
        flag=!flag;
    }
    cout << cnt << '\n';
   }

return 0;
}

No comments:

Post a Comment