結果
問題 |
No.8114 Prime Checker+1
|
ユーザー |
![]() |
提出日時 | 2025-02-22 10:49:37 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,232 bytes |
コンパイル時間 | 27,379 ms |
コンパイル使用メモリ | 401,992 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-22 10:50:07 |
合計ジャッジ時間 | 28,776 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
use proconio::{input, marker::Bytes}; use reprol::math::{is_prime::IsPrime, radix::FromRadix}; fn main() { input! { n: Bytes, } if n.len() < 18 { let n = n .into_iter() .map(|c| (c - b'0') as u32) .collect::<Vec<_>>() .from_radix(10); println!("0\n{}", if n.is_prime() { "Yes" } else { "No" }); return; } if *n.last().unwrap() % 2 == 0 { println!("0\nNo"); } else { println!("1\nNo"); } } #[allow(dead_code)] pub mod reprol { pub mod math { pub mod is_prime { pub trait IsPrime { fn is_prime(self) -> bool; } macro_rules! impl_integer { ($($ty:ident),*) => {$( impl IsPrime for $ty { fn is_prime(self) -> bool { self >= 2 && (2..).take_while(|i| i * i <= self).all(|i| self % i != 0) } } )*}; } impl_integer! { u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize } } pub mod radix { pub trait ToRadix { fn to_radix(self, base: Self) -> Vec<u32>; } pub trait FromRadix { type Output; fn from_radix(&self, n: u32) -> Self::Output; } macro_rules! impl_integer { ($($ty:ident),*) => {$( impl ToRadix for $ty { fn to_radix(self, base: Self) -> Vec<u32> { if self == 0 { return vec![0]; } let mut n = self; let mut res = Vec::new(); while n > 0 { let x = (n % base) as u32; res.push(x); n /= base; } res.reverse(); res } } )*}; } impl_integer! { u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize } impl FromRadix for String { type Output = u64; fn from_radix(&self, n: u32) -> Self::Output { u64::from_str_radix(self, n).unwrap() } } impl FromRadix for &str { type Output = u64; fn from_radix(&self, n: u32) -> Self::Output { u64::from_str_radix(self, n).unwrap() } } impl FromRadix for [u32] { type Output = u64; fn from_radix(&self, n: u32) -> Self::Output { let n = n as u64; let mut res = 0; let mut base = 1; for &e in self.iter().rev() { res += e as u64 * base; base *= n; } res } } } } }