summaryrefslogtreecommitdiff
path: root/lab1
diff options
context:
space:
mode:
Diffstat (limited to 'lab1')
-rw-r--r--lab1/Cargo.lock58
-rw-r--r--lab1/Cargo.toml1
-rw-r--r--lab1/src/main.rs60
3 files changed, 58 insertions, 61 deletions
diff --git a/lab1/Cargo.lock b/lab1/Cargo.lock
index 1281335..006d67e 100644
--- a/lab1/Cargo.lock
+++ b/lab1/Cargo.lock
@@ -3,63 +3,5 @@
version = 3
[[package]]
-name = "az"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
-
-[[package]]
-name = "gmp-mpfr-sys"
-version = "1.4.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea3f42dadb6c75f122e9aa87e757ef11d4282f664c9f2e6476a9c2c8970f9d19"
-dependencies = [
- "libc",
- "winapi",
-]
-
-[[package]]
name = "lab1"
version = "0.1.0"
-dependencies = [
- "rug",
-]
-
-[[package]]
-name = "libc"
-version = "0.2.134"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
-
-[[package]]
-name = "rug"
-version = "1.17.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "203180f444c95eac53586ed04793ecf6454c5d28f9eca8eead815fc19e136c47"
-dependencies = [
- "az",
- "gmp-mpfr-sys",
- "libc",
-]
-
-[[package]]
-name = "winapi"
-version = "0.3.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
-dependencies = [
- "winapi-i686-pc-windows-gnu",
- "winapi-x86_64-pc-windows-gnu",
-]
-
-[[package]]
-name = "winapi-i686-pc-windows-gnu"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
-
-[[package]]
-name = "winapi-x86_64-pc-windows-gnu"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/lab1/Cargo.toml b/lab1/Cargo.toml
index 1370852..b71c28d 100644
--- a/lab1/Cargo.toml
+++ b/lab1/Cargo.toml
@@ -6,4 +6,3 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rug = "1.17"
diff --git a/lab1/src/main.rs b/lab1/src/main.rs
index e7a11a9..bae0284 100644
--- a/lab1/src/main.rs
+++ b/lab1/src/main.rs
@@ -1,3 +1,59 @@
-fn main() {
- println!("Hello, world!");
+use std::io;
+use std::io::Write;
+
+fn egcd(a: i64, b: i64) -> (i64, i64, i64) {
+ if a == 0 {
+ return (b, 0, 1);
+ }
+ let p = egcd(b % a, a);
+ let d = p.0;
+ let x1 = p.1;
+ let y1 = p.2;
+ let x = y1 - (b / a) * x1;
+ let y = x1;
+ return (d, x, y);
+}
+
+fn main() -> io::Result<()> {
+ let stdin = io::stdin();
+
+ print!("Введите модуль m: ");
+ io::stdout().flush().unwrap();
+ let mut m = String::new();
+ stdin.read_line(&mut m)?;
+ let mut m = m.trim_end().parse::<i64>().unwrap();
+
+ print!("Введите a: ");
+ io::stdout().flush().unwrap();
+ let mut a = String::new();
+ stdin.read_line(&mut a)?;
+ let mut a = a.trim_end().parse::<i64>().unwrap() % m;
+
+ print!("Введите b: ");
+ io::stdout().flush().unwrap();
+ let mut b = String::new();
+ stdin.read_line(&mut b)?;
+ let mut b = b.trim_end().parse::<i64>().unwrap() % m;
+
+ let (d, _, _) = egcd(a, m);
+ if b % d != 0 {
+ println!("Сравнение не имеет решений");
+ } else {
+ println!("Сравнение имеет {d} решений");
+ a /= d;
+ b /= d;
+ m /= d;
+
+ let (_, x, _) = egcd(a, m);
+ let mut x0 = (x * b) % m;
+ if x0 < 0 {
+ x0 = m + x0;
+ }
+ for i in 0..d {
+ print!("{} ", x0 + m * i);
+ }
+ println!("");
+ }
+
+ return Ok(());
}