Skip to content

Instantly share code, notes, and snippets.

@ashiato45
Created February 8, 2021 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashiato45/3cb4430ca1f3996552cfc584ba1272e2 to your computer and use it in GitHub Desktop.
Save ashiato45/3cb4430ca1f3996552cfc584ba1272e2 to your computer and use it in GitHub Desktop.
fn divmod(a: i64, b: i64) -> (i64, i64){
let (q, r) = (a/b, a%b);
if r < 0{
return (q-1, r+b);
}else{
return (q, r);
}
}
fn divdown(a: i64, b: i64) -> i64{
return divmod(a, b).0;
}
fn divup(a: i64, b: i64) -> i64{
let (p, q) = divmod(a, b);
if q == 0{
return p;
}else{
return p + 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment