text: Sum of all numbers divisible by 6 in a given range | C # program to find sum of numbers divisible by 6 in a given range . ; function to calculate the sum of all numbers divisible by 6 in range L - R . . ; no of multiples of 6 upto r ; no of multiples of 6 upto l - 1 ; summation of all multiples of 6 upto r ; summation of all multiples of 6 upto l - 1 ; returns the answer ; driver program
code: using System ; class GFG { static int sum ( int L , int R ) { int p = R / 6 ; int q = ( L - 1 ) / 6 ; int sumR = 3 * ( p * ( p + 1 ) ) ; int sumL = ( q * ( q + 1 ) ) * 3 ; return sumR - sumL ; } public static void Main ( ) { int L = 1 , R = 20 ; Console . WriteLine ( sum ( L , R ) ) ; } }