var countDigitOne = function(n) {

var sum = 0;

var x = 1;

while(x<=n) {

var upNum = Math.floor(n/(10*x));
var lowNum = n % (10*x);

var vs = Math.floor(lowNum/x) - 1;

if(vs>0) {

sum += (upNum + 1) * x;

} else if (vs===0) {

sum += upNum

*x + lowNum%x + 1;*

} else if (vs<0) { //vs==-1

sum += upNumx;

} else if (vs<0) { //vs==-1

sum += upNum

}

x = x * 10;

}

return sum;

};