Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // { Driver Code Starts
- #include <bits/stdc++.h>
- using namespace std;
- // } Driver Code Ends
- class Solution {
- public:
- int bisection(double x) {
- double l = 0, r = x, mid;
- int count = 64;
- while (count--) {
- mid = (l + r) / 2.0;
- if (mid * mid == x) {
- return mid;
- }
- if ((mid * mid) < x) {
- l = mid;
- } else {
- r = mid;
- }
- }
- return floor(mid);
- }
- int countSquares(int N) {
- // code here
- int n;
- cin >>
- int res = bisection(n - 1);
- int count = 0;
- for (int i = 1; i <= res; i++) {
- if (pow(i, 2) < n) {
- count++;
- }
- }
- return count;
- }
- };
- // { Driver Code Starts.
- int main() {
- int t;
- cin >> t;
- while (t--) {
- int N;
- cin>>N;
- Solution ob;
- cout << ob.countSquares(N) << endl;
- }
- return 0;
- } // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement