Compatibility with ancient Rust version used by Google

main
Inga 🏳‍🌈 4 years ago
parent dec5280700
commit f38f8b1296
  1. 12
      0410-1A/task2-primetime/src/main.rs

@ -1,12 +1,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::{io::{self, BufRead}}; use std::{io::{self, BufRead}};
const PRIMES: [u16; 95] = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499]; fn factorize(mut number: u16, primes: &[u16]) -> Option<HashMap<u16, u16>> {
fn factorize(mut number: u16) -> Option<HashMap<u16, u16>> {
let mut result = HashMap::new(); let mut result = HashMap::new();
for &prime in &PRIMES { for &prime in primes.iter() {
let mut count = 0; let mut count = 0;
while (number % prime) == 0 { while (number % prime) == 0 {
count += 1; count += 1;
@ -26,10 +24,12 @@ fn factorize(mut number: u16) -> Option<HashMap<u16, u16>> {
} }
fn factorize_all() -> HashMap<u16, HashMap<u16, u16>> { fn factorize_all() -> HashMap<u16, HashMap<u16, u16>> {
let primes: Vec<u16> = vec![2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499];
let mut result = HashMap::new(); let mut result = HashMap::new();
for i in 1..u16::MAX { for i in 1..std::u16::MAX {
match factorize(i) { match factorize(i, &primes) {
Some(factors) => { Some(factors) => {
result.insert(i, factors); result.insert(i, factors);
}, },

Loading…
Cancel
Save