Skip to content

Instantly share code, notes, and snippets.

@MikuroXina
Created May 11, 2025 18:26
Show Gist options
  • Save MikuroXina/9191231138f8eddfd0cfc218a2efd312 to your computer and use it in GitHub Desktop.
Save MikuroXina/9191231138f8eddfd0cfc218a2efd312 to your computer and use it in GitHub Desktop.
Finds the ceiling value of square root with Rust.
/// Finds the ceiling value of square root of `n`.
pub fn ceil_sqrt(n: i64) -> i64 {
let mut base = (n as f64).sqrt() as i64 - 1;
while (base + 1) * (base + 1) <= n {
base += 1;
}
base
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment