Created
January 24, 2020 15:32
-
-
Save rust-play/09ad2e1f3ce4256596e384813d86c942 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
use std::cmp::max; | |
use rayon::prelude::*; | |
fn max_k(n: u64) -> u64 { | |
let p = n as f64; | |
return ((((8.0f64*p)+1.0f64).sqrt()-1.0f64)/2.0f64) as u64; | |
} | |
fn f(n: u64, k: &u64) -> u64 { | |
let total = (k*(k+1))/2; | |
max(1+((n-total)/k), 0) | |
} | |
fn F(n: u64) -> u64 { | |
[1..max_k(n)].par_iter().map(|x| f(n, x)).sum() | |
} | |
fn main() { | |
let k = f(100, &13); | |
println!("{}", k); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment