This is a creation in Article, where the information may have evolved or changed.
/* Compare for a moment
: http://blog.csdn.net/iilovetopview/article/details/43745059
Go is less computationally efficient than D (LDC compiler 0.15.1 (LLVM3.6, MSVC64)).
Solve the problem by using the "mathematical Formula" method:
There is an integer n, which writes a function f (n), which returns the number of "1" that occurs between 0 and N.
For example f (13) = 6, now f (1) = 1, ask the next largest f (n) =n n is what?
*/
Package Mainimport ("FMT" "Time" "math") var aa map[int]intvar Ac []intfunc Main () {FMT. Println ("Go Language"} wait for some minutes,will found Next Fn (n) = n, the n is: ") N: = 1count: =0pos: = 0t: =time . Now () for n =1;n<200000;n++ {AA = Do (map[int]int) Ac = make ([]int,10) pos = Fn (n) if n = = pos {count++fmt. Println ("N is:", N, "Fn (n) is:", POS) if (count >1) {break}}}fmt. Println ("Time is:", time.) Now (). Sub (t). String ()) fmt. PRINTLN (N, "Stop") fmt. Println ("Test 199981 is:", Fn_test (199981))} func Fn (n int) int {i:=0y:=0for x: =n;x>=1;x/=10 {y=x%10aa[i] =yac[i] =yi+ +}AC = ac[0:i]//key M: = Len (Ac) -1h: =aa[m]if (N%gpow (m) = = 0) {return Fna (h,m)}else{return Fna (h,m) +FNB (m-1)}}func Fna ( H int,m int) int {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) {R Eturn 1} else{return Gpow (M) +h*m*gpow (M-1)}}} func FnB (m int) int {...//code slightly return sum + FnB (m-1)}func gpow (m int) int {return int (math. POW10 (m))}/*------------test-------------*/func fn_test (n int) int {total:= 0for i:=0;i<=n;i++ {Total + = count (i)}return total}func count (n int) int {num:=0for t:= n;t >=1;t=t/10 {if (t%10 = = 1) {Num++}}return num}