-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1929. 소수 구하기 #12, not complete, 20230112
- Loading branch information
Dongsoon Shin
committed
Jan 12, 2023
1 parent
dafa03e
commit 761a444
Showing
1 changed file
with
38 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
use std::io; | ||
|
||
fn main() { | ||
let mut line = String::new(); | ||
io::stdin().read_line(&mut line).expect(""); | ||
let limit = 100; | ||
// let mut line = String::new(); | ||
// io::stdin().read_line(&mut line).expect(""); | ||
|
||
let inputs: Vec<i32> = line.split_whitespace() | ||
.map(|f| f.parse().expect("")) | ||
.collect(); | ||
let mut is_prime = vec![true; limit + 1]; | ||
is_prime[0] = false; | ||
if limit >= 1 { | ||
is_prime[1] = false | ||
} | ||
|
||
let mut m = inputs[0]; | ||
let mut n = inputs[1]; | ||
for num in 2..limit+1 { | ||
if is_prime[num] { | ||
let mut multiple = num * num; | ||
println!("{}", multiple); | ||
while multiple <= limit { | ||
is_prime[multiple] = false; | ||
multiple = num; | ||
} | ||
} | ||
} | ||
|
||
let mut arr:[i32;10000000]; | ||
let stop:i32 = arr.len() as i32; | ||
let v:Vec<usize> = is_prime.iter().enumerate() | ||
.filter_map(|(pr, &is_pr)| if is_pr { Some(pr) } else {None}) | ||
.collect(); | ||
|
||
// how can initilize array in Rust? | ||
for i in 0..stop { | ||
arr[i] = i; | ||
for i in 5..10 { | ||
if is_prime[i] { | ||
println!("{}", v[i]); | ||
} | ||
} | ||
|
||
// let inputs: Vec<usize> = line.split_whitespace() | ||
// .map(|f| f.parse().expect("")) | ||
// .collect(); | ||
|
||
// let mut m:usize = inputs[0]; | ||
// let mut n:usize = inputs[1]; | ||
|
||
// for index in m..n { | ||
// if is_prime[index] { | ||
// println!("{}", index); | ||
// } | ||
// } | ||
} |