Count of triplets till N whose product is at most N | C ++ program for the above approach ; Function to find number of triplets ( A , B , C ) having A * B * C <= N ; Stores the count of triplets ; Iterate a loop fixing the value of A ; Iterate a loop fixing the value of A ; Find the total count of triplets and add it to cnt ; Return the total triplets formed ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTriplets ( int N ) { int cnt = 0 ; for ( int A = 1 ; A <= N ; ++ A ) { for ( int B = 1 ; B <= N / A ; ++ B ) { cnt += N / ( A * B ) ; } } return cnt ; } int main ( ) { int N = 2 ; cout << countTriplets ( N ) ; return 0 ; }