"Template" calculates the number of 1
1 __int64 Countone (__int64 N)2 {3__int64 count =0;4 if(n = =0)5Count =0;6 Else if(N >1&& N <Ten)7Count =1;8 Else9 {Ten__int64 highest =N; One__int64 bit =0; A while(Highest >=Ten) - { -highest = highest/Ten; thebit++; - } - -__int64 weight = (__int64) POW (Ten, bit); + if(Highest = =1) - { +Count = Countone (weight-1) + Countone (n-weight) + N-weight +1; A } at Else - { -Count = highest * Countone (weight-1) + countone (n-highest * weight) +weight; - } - } - returncount; in } - or toPubliclong CountOne2 (LongN) + { - LongCount =0; the Longi =1; * LongCurrent =0, after =0, before =0; $ while((n/i)! =0)Panax Notoginseng { -Current = (n/i)%Ten; theBefore = n/(i *Ten); +after = N-(n/i) *i; A if(Current >1) theCount = Count + (before +1) *i; +else if (current = =0) -Count = Count + before *i; $else if (current = =1) $Count = Count + before * i + after +1; - -i = i *Ten; the } - returncount;Wuyi}
Number of templates calculated 1