Value required to be added to N to obtain the sum of first M multiples of K | C ++ program for the above approach ; Function to print the value to be added to N to obtain sum of first M multiples of K ; Store the sum of the first M multiples of K ; Store the value to be added to obtain N ; Driver Code ; Input
#include <iostream> NEW_LINE using namespace std ; static int printNumber ( int N , int K , int M ) { int sum = K * ( M * ( M + 1 ) / 2 ) ; return sum - N ; } int main ( ) { int N = 17 ; int K = 3 ; int M = 4 ; cout << printNumber ( N , K , M ) ; return 0 ; }