diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2022-10-06 14:10:52 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2022-10-06 14:10:52 +0400 |
| commit | 25a601c95c1e5957d425b6ffdacc583649e5ec5f (patch) | |
| tree | a9c88cf75b789089af329a8ddf3207c350999442 | |
| parent | 292ee3a5eafb96e6d17e6ca38cdf102d804e9743 (diff) | |
Добавлена третья лабораторная
| -rw-r--r-- | lab3/Cargo.lock | 65 | ||||
| -rw-r--r-- | lab3/Cargo.toml | 9 | ||||
| -rw-r--r-- | lab3/src/main.rs | 38 |
3 files changed, 112 insertions, 0 deletions
diff --git a/lab3/Cargo.lock b/lab3/Cargo.lock new file mode 100644 index 0000000..1281335 --- /dev/null +++ b/lab3/Cargo.lock @@ -0,0 +1,65 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +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/lab3/Cargo.toml b/lab3/Cargo.toml new file mode 100644 index 0000000..1370852 --- /dev/null +++ b/lab3/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "lab1" +version = "0.1.0" +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/lab3/src/main.rs b/lab3/src/main.rs new file mode 100644 index 0000000..01fae91 --- /dev/null +++ b/lab3/src/main.rs @@ -0,0 +1,38 @@ +use rug::{Complete, Integer}; +use std::io; + + +fn main() { + let mut p = String::new(); + let stdin = io::stdin(); + match stdin.read_line(&mut p) { + Ok(_) => (), + Err(_) => { + println!("Произошла ошибка при чтении из стандартного ввода"); + } + } + + let p = match Integer::parse(p) { + Ok(parsed) => parsed.complete(), + Err(_) => { + println!("Не удалось считать число"); + return () + } + }; + + let mut fact = Integer::from(1u32).clone(); + let mut i = p.clone() - 1; + while i != 1 { + fact *= &i; + i -= 1; + } + fact += 1; + + let (_, r) = fact.div_rem_ref(&p).complete(); + if r == 0 { + println!("Число {} является простым", &p); + } + else { + println!("Число не является простым"); + } +} |