Queries on sum of odd number digit sums of all the factors of a number | Javascript Program to answer queries on sum of sum of odd number digits of all the factors of a number ; finding sum of odd digit number in each integer . ; for each number ; using previous number sum , finding the current number num of odd digit also , adding last digit if it is odd . ; finding sum of sum of odd digit of all the factors of a number . ; for each possible factor ; adding the contribution . ; Wrapper function ; Driver Program
var N = 1000005 ; function sumOddDigit ( digitSum ) { for ( var i = 1 ; i < N ; i ++ ) { digitSum [ i ] = digitSum [ parseInt ( i / 10 ) ] + ( i & 1 ) * ( i % 10 ) ; } } function sumFactor ( digitSum , factorDigitSum ) { for ( var i = 1 ; i < N ; i ++ ) { for ( var j = i ; j < N ; j += i ) { factorDigitSum [ j ] += digitSum [ i ] ; } } } function wrapper ( q , n ) { var digitSum = Array ( N ) . fill ( 0 ) ; var factorDigitSum = Array ( N ) . fill ( 0 ) ; sumOddDigit ( digitSum ) ; sumFactor ( digitSum , factorDigitSum ) ; for ( var i = 0 ; i < q ; i ++ ) document . write ( factorDigitSum [ n [ i ] ] + " " ) ; } var q = 2 ; var n = [ 10 , 36 ] ; wrapper ( q , n ) ;