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
- // Function to find square root
- // x: element to find square root
- class Solution{
- public:
- long long int floorSqrt(long long int x)
- {
- double l = 0, r = x;
- int count = 64;
- double mid;
- while (count--) {
- mid = (l + r) / 2.0;
- if (mid * mid == x) {
- return mid;
- }
- if ((mid * mid) < x) {
- l = mid;
- } else {
- r = mid;
- }
- }
- return mid;
- }
- };
- // { Driver Code Starts.
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- long long n;
- cin>>n;
- Solution obj;
- cout << obj.floorSqrt(n) << endl;
- }
- return 0;
- }
- // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement