Find sum of digits in factorial of a number | Function to multiply x with large number stored in vector v . Result is stored in v . ; Calculate res + prev carry ; updation at ith position ; Returns sum of digits in n ! ; One by one multiply i to current vector and update the vector . ; Find sum of digits in vector v [ ] ; Driver code
def multiply ( v , x ) : NEW_LINE INDENT carry = 0 NEW_LINE size = len ( v ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT res = carry + v [ i ] * x NEW_LINE v [ i ] = res % 10 NEW_LINE carry = res // 10 NEW_LINE DEDENT while ( carry != 0 ) : NEW_LINE INDENT v . append ( carry % 10 ) NEW_LINE carry //= 10 NEW_LINE DEDENT DEDENT def findSumOfDigits ( n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT multiply ( v , i ) NEW_LINE DEDENT sum = 0 NEW_LINE size = len ( v ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT sum += v [ i ] NEW_LINE DEDENT return sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 1000 NEW_LINE print ( findSumOfDigits ( n ) ) NEW_LINE DEDENT