My issue
I am not able to find why this code is giving WA.
include <bits/stdc++.h>
using namespace std;
typedef long long ll;
define endl ‘\n’
int main() {
// your code goes here
int t; cin>>t;
while(t–){
ll a, b; cin>>a>>b;
if(a==b) cout<<0<<endl;
else{
ll d = abs(a-b);
ll sum = 0, i=1;
while(sum<d){
sum += i;
i++;
}
ll moves = i-1;
if((moves%2) == (d%2)) cout<<moves<<endl;
else cout<<moves+1<<endl;
}
}
return 0;
}
My code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int main() {
// your code goes here
int t; cin>>t;
while(t--){
ll a, b; cin>>a>>b;
if(a==b) cout<<0<<endl;
else{
ll d = abs(a-b);
ll sum = 0, i=1;
while(sum<d){
sum += i;
i++;
}
ll moves = i-1;
if((moves%2) == (d%2)) cout<<moves<<endl;
else cout<<moves+1<<endl;
}
}
return 0;
}
Problem Link: Equality Etiquette Practice Coding Problem - CodeChef