/* 比较一下
:http://blog.csdn.net/iilovetopview/article/details/43745059
发现还是D语言的快。
*/
use std::time::duration::Duration;
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
{
..... //代码略
return sum + fnB(m-1,va);
}
fn gPow(m: usize) ->usize
{
return 10.pow(m);
}