結果
| 問題 |
No.1058 素敵な数
|
| コンテスト | |
| ユーザー |
yukyu
|
| 提出日時 | 2021-03-14 17:23:43 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,474 bytes |
| コンパイル時間 | 13,437 ms |
| コンパイル使用メモリ | 399,808 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 07:03:11 |
| 合計ジャッジ時間 | 14,288 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 WA * 1 |
ソースコード
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;
fn main() {
exec(read());
}
fn exec(i: usize) {
let a = get_prime_list();
println!("{}", get(a)[i - 1]);
}
fn get_prime_list() -> Vec<i64> {
let acc: Vec<i64> = vec![];
let start: i64 = 100001;
rec_prime(start, acc)
}
fn rec_prime(mut current: i64, mut acc: Vec<i64>) -> Vec<i64> {
if acc.len() >= 5 {
return acc;
} else {
if is_prime(current) {
acc.push(current);
}
current = current + 1;
rec_prime(current, acc)
}
}
fn is_prime(current: i64) -> bool {
let target = (current as f64).sqrt() as i64 + 1;
let mut i: i64 = 2;
while i <= target {
if current % i == 0 {
return false;
}
i += 1;
}
true
}
fn get(l: Vec<i64>) -> Vec<i64> {
let mut a: Vec<i64> = vec![];
a.push(1);
for i in &l {
for j in &l {
a.push((i * j) as i64);
}
}
let v: HashSet<i64> = a.iter().cloned().collect();
let mut r: Vec<i64> = v.into_iter().collect();
r.sort();
r
}
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("failed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().expect("failed to parse token")
}
yukyu