| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
0ms 水过#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
const double eps = (1e-9);
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int t, n, m;
int d, ans, k;
scanf("%d", &t);
while(t --)
{
scanf("%d%d", &n, &m);
if(n == m) { printf("0\n"); continue; }
d = m - n;
k = int(floor(sqrt(1.0*d))-eps)+1;
ans = k + k - 1;
d = d - k * k;
if(!d) printf("%d\n", ans);
else if(d > k) printf("%d\n", ans + 2);
else printf("%d\n", ans + 1);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator