Given an array of N non-negative integers and a value L, find the largest perfect square in the array that does not exceed L. If none exists, print -1.
SquareFinder extends Thread; each thread holds localBest (default -1).x ≥ 0 is a perfect square if r = (int) Math.sqrt(x) satisfies r*r == x or (r+1)*(r+1) == x.localBest (only considering values x ≤ L that are perfect squares).join(), take the max of all localBest values. Print it.0 ≤ values ≤ 10⁹
The largest perfect square ≤ L in the array, or -1.
Ví dụ:
Đầu vào:
6
1 4 7 9 16 25
2
20
Đầu ra:
16
Giải thích:
Đầu vào:
4
3 5 7 11
2
100
Đầu ra:
-1
Giải thích:
Đầu vào:
5
0 1 4 9 16
5
0
Đầu ra:
0
Giải thích:
Đầu vào:
3
100 121 144
2
130
Đầu ra:
121
Giải thích:
Đang tải editor...