Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //integer bisection.
- class Solution {
- public:
- int countSquares(int N) {
- N--;
- long long l=0,r=N,ans;
- while(l<=r)
- {
- if(ans*ans>N) break;
- long long mid=(l+r)/2;
- if(mid*mid>N) r=mid-1;
- else
- {
- ans=mid;
- l=mid+1;
- }
- }
- return ans;
- }
- };
- //fractional bisection
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long int x;
- cin>>x;
- x--;
- double l=0,r=x;
- for(int i=0;i<100;i++)
- {
- double mid=(l+r)/2.0;
- if(mid*mid>x) r=mid;
- else l=mid;
- }
- cout<<floor(l);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement