paranid5

Простые числа

Jun 3rd, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.72 KB | None | 0 0
  1. use std::io;
  2.  
  3. fn input() -> i32 {
  4.     let mut _s: String = String::new();
  5.     io::stdin().read_line(& mut _s).expect("read_line");
  6.     return _s.trim().parse().expect("convert") // return не обязателен, просто удобно
  7. }
  8. fn iz(mut _k: i32) -> bool {
  9.     let _sqr: i32 = ((_k as f64).sqrt()) as i32;
  10.     for _i in 2..(_sqr + 1) {
  11.         if _k % _i == 0 {
  12.             return false
  13.         }
  14.     }
  15.     return true
  16. }
  17. fn main() {
  18.     let mut _m: i32 = 0;
  19.     _m = input(); // начало (>=2)
  20.     let mut _n: i32 = 0;
  21.     _n = input(); // конец
  22.     while _m <= _n {
  23.         if iz(_m) {
  24.             println!("{}",_m);
  25.         }
  26.         _m += 1;
  27.     }
  28. }
Add Comment
Please, Sign In to add comment