find out how many zeros there are between 1 and 1 million
find out how many zeros there are between 1 and 1 million
-sharp PHP
echo strlen(preg_replace('/[1-9]/', '', implode('', range(1, 1000000))));
first consider 000000 ~ 999999
(assuming you don't ignore the previous 0). There are a total of 10 ^ 6 * 6
numbers, and all 10 numbers are symmetrical. Therefore, there are a total of 10 ^ 6 * 6 code > zeros. But for the number less than 6 digits, we need to remove the 0 on the sixth bit, which has a total of 10 ^ 5, and for the number of less than 5 digits, we have to remove the 0 on the fifth bit, which has a total of 10 ^ 4.
finally add six zeros of 1 million.
so 6 * 10 ^ 5-10 ^ 5-10 ^ 4.-10-1 + 6 = 488895
Press the PHP of @ Masterton to change to JS is
var a=[], i;
for(i=0; i< 1000000; iPP) {a[i] = i+1;}
num = a.join('').replace(/[1-9]/g,'').length;
the result is also 488895
encounters a javascript algorithm problem, which requires that find out all prime factors of a number algorithm I designed: function primeFactors(n){ var factors = []; var divisor = 3; if (n % 2==0) factors.push(2); while(n>5){ ...
for example, if you want to move from 0 to 100 1px at this speed, you can move x coordinates + 1 per frame. What if you want to move obliquely from 0 ~ 0 to 100 ~ ~ 20 at this speed? ...
Let the bullets be fired according to the direction of the mouse click, just like those who are good at fishing ...
encounters an algorithm; similar to var a = [1 br > how to deal with it into a two-digit array [[1], [2], [4Power4], [5Power5]] < beacon > I wrote it myself: uh. how to deal with it into a two-digit array [[1], [2], [4parry 4], [5pjre 5]]. Loop twice, n...
has a select drop-down box with five option elements with value values from 1 to 5 <select> <option value="1">1< option> <option value="2">2< option> <option value="3">3< ...
given a non-empty array of integers, each element appears twice except for an element that appears only once. Find the element that only appears once. example 1: : [2,2,1] : 1 example 2: : [4,1,2,1,2] : 4 the answer with the highest running effici...
let arrs=[102,233,45,350,130,220,195,240] I want arrs to split into two groups, but I want the sum of the two groups to be as close as possible. The smaller the difference, the better. My own idea is to re-sort, from small to large, and then judge the s...
I want to output all possible routes, but in the end, I only output one route. I haven t figured out Orz for a long time. the following is the source code: ma mbmb.fill(0); 0 1 (x0,y0) position=[] direction=[[-1,0],[0,-1],[1,0],[0,1...
use JavaScript to build a segment tree, and recursion is used in the construction process. This should make the call stack overflow. I wonder if there is any other way to solve this problem. < H1 > Code < H1 > ...
data A: [ { "id":340, "name":"", "sub":[ { "id":341, "name":"" }, { &q...
for example: [1, 2, 3, 4, 5] after sorting: 1, 3, 5, 2, 4 Note: does not create a new array , that is, it is changed on the basis of the original array. ...
php algorithm-- catching water droplets A novice PHP programmer, who has been on the job for half a year and is still hovering in endless additions, deletions, modifications and data optimization, has recently been brought into the algorithm pit by th...
directory tree initialization initially returns only a two-tier structure. [ { name: , path: , id: 1, childs: 2, children: [ { name: 01 , path: 01 , id: 2, ...
there are now such data objects arr = [ {] start: 1, end: 12 }, { start: 2, end: 5 }, { start: 6, end: 10 }, . ] how to determine whether the start and end of each object are continuous for example, the above situation is incorrect, because 1-12 c...
What is the data structure corresponding to Object in js? What is its logical structure and physical structure? ...
topic description as shown in the question, if you know the GPS coordinates of five points, how to find the sixth point and minimize the sum of the distances from the other five points, and find out his GPS coordinates would like to ask if you have ...