/* Compare for a moment
: http://blog.csdn.net/iilovetopview/article/details/43745059
It's fast to find the D language.
*/
Use Std::time::d uration::D uration;
Use Std::num::int;
Use Std::collections::hashmap;
Use Std::collections::hash::map;
Pub struct Va {
Pub ac:vec<usize>
Pub aa:hashmap<usize, Usize>
}
fn Main () {
Let R = Duration::span (FNX);
println! ("Time: {} milliseconds", R.num_milliseconds ());
}
fn FNX ()
{
Let (Mut pos,mut N, mut count) = (0,1,0);
while (n >0)
{
Let Mut vc = Va{ac:vec![],aa:hashmap::new (),};
pos = Fx (N,VC);
if (n = = pos)
{
Count +=1;
println! ("N is: {0}, Fn (n) is:{1}", N,pos);
if (count >1) {break;}
}
N+=1;
if (n >200000) {break;} //
}
}
fn Fx (N:usize,mut va:va), usize
{
Let (Mut i,mut y,mut L) = (0,0,0);
Let mut x = n;
while (x>=1)
{
y=x%10;
Va.aa.insert (I,y);
Va. Ac.push (y);
x/= 10;
I+=1;
}
Let mut m = Va. Ac.len ()-1;
Let (mut result, mut h) = (0,0);
H =va.aa[m];
if (N%gpow (m) = = 0) {return FnA (h,m);}
else {return FnA (h,m) +FNB (M-1,VA);}
}
fn FnA (h:usize,m:usize)->usize
{
if (h = = 0) {return 0;}
else if (h==1) {if (M = = 0) {return 1;} else {return M*gpow (m-1) +1;}}
else {if (M = = 0) {return 1;} else {return Gpow (m) +h*m*gpow (m-1);}}
}
fn FnB (M:usize,mut va:va)->usize
{
...//code slightly
return sum + FnB (M-1,VA);
}
fn Gpow (m:usize)->usize
{
Return 10.pow (m);
}
Rust Language Solution Question 1