Count divisors which generates same Quotient and Remainder | C ++ program of the above approach ; Function to calculate the count of numbers such that it gives same quotient and remainder ; Stores divisor of number N . ; Iterate through numbers from 2 to sqrt ( N ) and store divisors of N ; As N is also divisor of itself ; Iterate through divisors ; Checking whether x satisfies the required condition ; Print the count ; Driver Code ; Given N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countDivisors ( long long int n ) { int count = 0 ; vector < long long int > divisor ; for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) divisor . push_back ( i ) ; else { divisor . push_back ( i ) ; divisor . push_back ( n / i ) ; } } } divisor . push_back ( n ) ; for ( auto x : divisor ) { x -= 1 ; if ( ( n / x ) == ( n % x ) ) count ++ ; } cout << count ; } int main ( ) { long long int N = 1000000000000 ; countDivisors ( N ) ; return 0 ; }