From 1136cb55620a16a93f9847d6d670503857900c91 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Thu, 6 Oct 2022 14:48:46 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=87=D0=B5=D1=82=D0=B2=D1=91=D1=80=D1=82=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab4/Cargo.lock | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lab4/Cargo.toml | 9 ++++++++ lab4/src/main.rs | 43 +++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 lab4/Cargo.lock create mode 100644 lab4/Cargo.toml create mode 100644 lab4/src/main.rs (limited to 'lab4') 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!("Число не является простым"); + } +} -- cgit v1.2.3