summaryrefslogtreecommitdiff
path: root/c/0069/main.c
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-09-06 22:54:30 +0800
committerMistivia <i@mistivia.com>2025-09-06 22:54:30 +0800
commit2f1fe8ed723af972a10e208ea3c798dfba48b4d7 (patch)
tree13eef8823762596cfbee002d9266687653684bf3 /c/0069/main.c
parenta01a74b01c507ff98a7ba87718a5fa4b1c21fe85 (diff)
solve 69
Diffstat (limited to 'c/0069/main.c')
-rw-r--r--c/0069/main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/c/0069/main.c b/c/0069/main.c
new file mode 100644
index 0000000..86aab4a
--- /dev/null
+++ b/c/0069/main.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdint.h>
+
+int mySqrt(int x) {
+ int64_t t = x;
+ int64_t ln = 0, rn = x;
+ while (ln <= rn) {
+ int64_t mid = ln + (rn - ln) / 2;
+ if (mid * mid < x) {
+ if ((mid + 1) * (mid + 1) > x) {
+ return mid;
+ }
+ ln = mid + 1;
+ } else if (mid * mid > x) {
+ rn = mid - 1;
+ } else {
+ return mid;
+ }
+ }
+ return -1;
+}
+
+int main() {
+ printf("%d\n", mySqrt(9));
+ return 0;
+}