Queries on sum of odd number digit sums of all the factors of a number | C # 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 code
using System ; class GFG { static int N = 1000005 ; static void sumOddDigit ( int [ ] digitSum ) { for ( int i = 1 ; i < N ; i ++ ) { digitSum [ i ] = digitSum [ i / 10 ] + ( i & 1 ) * ( i % 10 ) ; } } static void sumFactor ( int [ ] digitSum , int [ ] factorDigitSum ) { for ( int i = 1 ; i < N ; i ++ ) { for ( int j = i ; j < N ; j += i ) { factorDigitSum [ j ] += digitSum [ i ] ; } } } static void wrapper ( int q , int [ ] n ) { int [ ] digitSum = new int [ N ] ; int [ ] factorDigitSum = new int [ N ] ; sumOddDigit ( digitSum ) ; sumFactor ( digitSum , factorDigitSum ) ; for ( int i = 0 ; i < q ; i ++ ) Console . Write ( factorDigitSum [ n [ i ] ] + " ▁ " ) ; } public static void Main ( ) { int q = 2 ; int [ ] n = new int [ ] { 10 , 36 } ; wrapper ( q , n ) ; } }