結果
| 問題 | No.312 置換処理 |
| コンテスト | |
| ユーザー |
sino
|
| 提出日時 | 2020-04-13 14:17:33 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,036 bytes |
| 記録 | |
| コンパイル時間 | 3,692 ms |
| コンパイル使用メモリ | 143,552 KB |
| 最終ジャッジ日時 | 2026-05-10 11:48:58 |
| 合計ジャッジ時間 | 4,522 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error: cannot explicitly dereference within an implicitly-borrowing pattern --> src/main.rs:92:22 | 92 | .filter(|(_, &flg)| flg) | ^ reference pattern not allowed when implicitly borrowing | = note: for more information, see <https://doc.rust-lang.org/reference/patterns.html#binding-modes> note: matching on a reference type with a non-reference pattern implicitly borrows the contents --> src/main.rs:92:18 | 92 | .filter(|(_, &flg)| flg) | ^^^^^^^^^ this non-reference pattern matches on a reference type `&_` help: match on the reference with a reference pattern to avoid implicitly borrowing | 92 | .filter(|&(_, &flg)| flg) | + error: could not compile `main` (bin "main") due to 1 previous error
ソースコード
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
#[allow(unused_macros)]
macro_rules! read {
([$t:ty] ; $n:expr) =>
((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
($($t:ty),+ ; $n:expr) =>
((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
([$t:ty]) =>
(rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
($t:ty) =>
(rl().parse::<$t>().unwrap());
($($t:ty),*) => {{
let buf = rl();
let mut w = buf.split_whitespace();
($(w.next().unwrap().parse::<$t>().unwrap()),*)
}};
}
#[allow(dead_code)]
fn rl() -> String {
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
buf.trim_end().to_owned()
}
fn main() {
let n = read!(usize);
let m = min_factor(n);
if m == n || m >= 3{
println!("{}", m);
}
else {
let m2 = min_factor(n/m);
if m2 == n/m {
if m2 >= 3 {
println!("{}", m2);
}
else {
println!("{}", n);
}
}
else {
for i in 3..n {
if n % i == 0 {
println!("{}", i);
return;
}
}
}
}
}
fn min_factor(n: usize) -> usize {
for p in primes((n as f64).sqrt() as usize + 1).iter() {
if n % p == 0 {
return *p;
}
};
n
}
fn primes(n: usize) -> Vec::<usize> {
if n < 2 {
return vec![];
}
let mut table = vec![true; n+1];
table[0] = false;
table[1] = false;
for i in 2..=(n as f64).sqrt() as usize {
if table[i] == false {
continue;
}
let mut j = i*i;
while j <= n {
table[j] = false;
j += i;
}
}
table
.iter()
.enumerate()
.filter(|(_, &flg)| flg)
.map(|(num, _)| num)
.collect()
}
sino