Count number of triplets ( a , b , c ) from first N natural numbers such that a * b + c = N | Java program to implement the above approach ; Function to find the count of triplets ( a , b , c ) with a * b + c = N ; Stores count of triplets of 1 st N natural numbers which are of the form a * b + c = N ; Iterate over the range [ 1 , N ] ; If N is divisible by i ; Update cntTriplet ; Update cntTriplet ; Driver code
import java . util . * ; class GFG { static int findCntTriplet ( int N ) { int cntTriplet = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( N % i != 0 ) { cntTriplet += N / i ; } else { cntTriplet += ( N / i ) - 1 ; } } return cntTriplet ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( findCntTriplet ( N ) ) ; } }