-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSherlock_and_Squares.cpp
54 lines (39 loc) · 1.04 KB
/
Sherlock_and_Squares.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Title : Sherlock_and_Squares.cpp
* Author : Tridib Samanta
* Created : 24-03-2020
* Link : https://www.hackerrank.com/challenges/sherlock-and-squares/problem
**/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin>> q;
while(q--) {
int a,b;
cin>> a >> b;
int total = 0;
int shuru = sqrt(a);
int khatam = sqrt(b);
if(shuru * shuru == a && khatam * khatam == b)
total = (khatam-shuru) + 1;
else if(shuru * shuru != a && khatam * khatam == b)
total = khatam - shuru;
else if(shuru * shuru == a && khatam * khatam != b)
total = (khatam - shuru) + 1;
else
total = khatam - shuru;
cout<< total << "\n";
}
return 0;
}