Sum of all odd factors of numbers in the range [ l , r ] | Python3 implementation of the approach ; Function to calculate the prefix sum of all the odd factors ; Add i to all the multiples of i ; Update the prefix sum ; Function to return the sum of all the odd factors of the numbers in the given range ; Driver code
MAX = 100001 ; NEW_LINE prefix = [ 0 ] * MAX ; NEW_LINE def sieve_modified ( ) : NEW_LINE INDENT for i in range ( 1 , MAX , 2 ) : NEW_LINE INDENT for j in range ( i , MAX , i ) : NEW_LINE INDENT prefix [ j ] += i ; NEW_LINE DEDENT DEDENT for i in range ( 1 , MAX ) : NEW_LINE INDENT prefix [ i ] += prefix [ i - 1 ] ; NEW_LINE DEDENT DEDENT def sumOddFactors ( L , R ) : NEW_LINE INDENT return ( prefix [ R ] - prefix [ L - 1 ] ) ; NEW_LINE DEDENT sieve_modified ( ) ; NEW_LINE l = 6 ; NEW_LINE r = 10 ; NEW_LINE print ( sumOddFactors ( l , r ) ) ; NEW_LINE