forked from PoeLoren/hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle City.cpp
39 lines (38 loc) · 891 Bytes
/
Circle City.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin >> n;
while(n--){
long long r, k;
cin >> r >> k;
long long s = static_cast<long long>(sqrt(r)) + 1;
long long l = 0;
long long sum = 0;
while(l <= s){
int t = l * l + s * s;
if(t == r){
if(l == 0)
sum += 4;
else
sum += 8;
l++;
s--;
}
else if(t < r)
l++;
else
s--;
}
if(sum <= k)
cout << "possible" << endl;
else
cout << "impossible" << endl;
}
return 0;
}