Count Pronic numbers from a given range | C ++ program for the above approach ; Function to count pronic numbers in the range [ A , B ] ; Check upto sqrt N ; If product of consecutive numbers are less than equal to num ; Return N - 1 ; Function to count pronic numbers in the range [ A , B ] ; Subtract the count of pronic numbers which are <= ( A - 1 ) from the count f pronic numbers which are <= B ; Driver Code ; Function call to count pronic numbers in the range [ A , B ]
#include <bits/stdc++.h> NEW_LINE using namespace std ; int pronic ( int num ) { int N = ( int ) sqrt ( num ) ; if ( N * ( N + 1 ) <= num ) { return N ; } return N - 1 ; } int countPronic ( int A , int B ) { return pronic ( B ) - pronic ( A - 1 ) ; } int main ( ) { int A = 3 ; int B = 20 ; cout << countPronic ( A , B ) ; return 0 ; }