wa了两次才纠正,虽然想法对了,还是要自己先多测几组数据
#include<iostream> #include<math.h> using namespace std; int main(){ int x,y; int n; cin>>n; while(n--){ cin>>x>>y; if(x==y){ cout<<"0"<<endl; continue; } int n = (int)sqrt((double)(y-x)); if(n==1) cout<<y-x<<endl; else cout<<2*n-1+(y-x-n*n)/n+(((y-x-n*n)%n)?1:0)<<endl; } }