UVA846-步数
#include <iostream> using namespace std; int main () { int m, n; int num; cin>>num; while(num--) { cin>>m>>n; int dis, step = 0; dis = n - m; if(dis == 0) { cout<<0<<endl; continue; } int k = 0; for(k = 0; k*k <= dis; k++); int ma = k-1; step = 2 * ma - 1; step += (dis - ma *ma) / ma; if((dis-ma*ma)%ma)step++; cout<<step<<endl; } return 0; } 数学题,找规律。对于m,n,找最大的k使得1+2+3+……K……+1 = n;若n == dis 最好, 如不等,就从k加,一直加到n == dis!!!