summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Guschin <guschin.drew@gmail.com>2022-10-06 14:48:46 +0400
committerAndrew Guschin <guschin.drew@gmail.com>2022-10-06 14:48:46 +0400
commit1136cb55620a16a93f9847d6d670503857900c91 (patch)
tree361e963d724853a01e6109228e6779713092b528
parent25a601c95c1e5957d425b6ffdacc583649e5ec5f (diff)
Добавлена четвёртая лабораторная
-rw-r--r--lab4/Cargo.lock65
-rw-r--r--lab4/Cargo.toml9
-rw-r--r--lab4/src/main.rs43
3 files changed, 117 insertions, 0 deletions
diff --git a/lab4/Cargo.lock b/lab4/Cargo.lock
new file mode 100644
index 0000000..1281335
--- /dev/null
+++ b/lab4/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/lab4/Cargo.toml b/lab4/Cargo.toml
new file mode 100644
index 0000000..1370852
--- /dev/null
+++ b/lab4/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/lab4/src/main.rs b/lab4/src/main.rs
new file mode 100644
index 0000000..d46480a
--- /dev/null
+++ b/lab4/src/main.rs
@@ -0,0 +1,43 @@
+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 is_prime = true;
+ for i in 1..4 {
+ let a: Integer = p.clone() - i;
+ if a <= 0 {
+ break;
+ }
+ let p_minus_1 = p.clone() - 1;
+ let r = Integer::from(a.pow_mod_ref(&p_minus_1, &p).unwrap());
+ if r != 1 {
+ is_prime = false;
+ break;
+ }
+ }
+
+ if is_prime {
+ println!("Число {} является простым", &p);
+ }
+ else {
+ println!("Число не является простым");
+ }
+}