Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- int good(unsigned long long x, unsigned long long key)
- {
- if (x * x > key || x == 4294967296)
- return 1;
- return 0;
- }
- unsigned long long int bin(unsigned long long key)
- {
- unsigned long long int left, right, mid;
- left = 0;
- right = 1;
- while (right * 2 <= 4294967296) {
- right *= 2;
- if (good(right, key))
- break;
- }
- while (right - left != 1) {
- mid = (left + right) / 2;
- if (good(mid, key))
- right = mid;
- else if (!good(mid, key))
- left = mid;
- }
- return left;
- }
- int main()
- {
- std::ifstream fin("input.txt");
- std::ofstream fout("output.txt");
- unsigned long long int input;
- while (fin >> input){
- fout << bin(input) << std::endl;
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment