diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2022-12-11 12:43:48 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2022-12-11 12:43:48 +0400 |
| commit | 032e1fa27ff9faa9a5d82624dbfc5fe8a48c339c (patch) | |
| tree | 40083b63867a6517254e9b27a3a81c8f9aac5d37 /lab5/src/utils.rs | |
| parent | a28703315e4628b41e1d7d1d0628189b44b656b8 (diff) | |
Добавлена 5 лабораторная
Diffstat (limited to 'lab5/src/utils.rs')
| -rw-r--r-- | lab5/src/utils.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lab5/src/utils.rs b/lab5/src/utils.rs new file mode 100644 index 0000000..34f87b3 --- /dev/null +++ b/lab5/src/utils.rs @@ -0,0 +1,32 @@ +pub fn powmod(x: u64, p: u64, m: u64) -> u64 { + let mut res = x; + for _ in 1..p { + res = (res * x) % m; + } + return res; +} + +pub fn adler64(buf: &[u8]) -> u64 { + let mod64 = 4294967291u64; + let mut s1 = 1u64; + let mut s2 = 0u64; + + for n in buf { + s1 = (s1 + *n as u64) % mod64; + s2 = (s2 + s1) % mod64; + } + return (s2 << 32) | s1; +} + +pub fn inverse_mod(x: i64, m: i64) -> i64 { + let (_, x, _) = extended_gcd(x, m); + return (x % m + m) % m; +} + +pub fn extended_gcd(a: i64, b: i64) -> (i64, i64, i64) { + if a == 0 { + return (b, 0, 1); + } + let (d, x, y) = extended_gcd(b % a, a); + return (d, y - (b / a) * x, x); +} |