Skip to content

Instantly share code, notes, and snippets.

@yeopgi
Created August 28, 2021 05:15
Show Gist options
  • Select an option

  • Save yeopgi/269f9db867acc2d56346f5fad957e1c8 to your computer and use it in GitHub Desktop.

Select an option

Save yeopgi/269f9db867acc2d56346f5fad957e1c8 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<cstdio>
using namespace std;
int warp(int dist) {
long long n, minN, powN, maxN, warpCount= 0;
for(n=1;;n++){
powN = n*n;
minN = powN - n + 1;
maxN = powN + 1 + n - 1;
if(minN<=dist && dist<=maxN){
if(minN<=dist && dist<=powN) warpCount = (n<<1) - 1;
else warpCount = n<<1;
break;
}
}
return warpCount;
}
int main() {
int t, x, y, dist; scanf("%d", &t);
while (t--) {
scanf("%d%d", &x, &y);
dist = y - x;
printf("%d\n", warp(dist));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment