Count of pairs of ( i , j ) such that ( ( n % i ) % j ) % n is maximized | C ++ implementation of the approach ; Function to return the count of required pairs ; Special case ; Number which will give the max value for ( ( n % i ) % j ) % n ; To store the maximum possible value of ( ( n % i ) % j ) % n ; Count of possible pairs ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countPairs ( int n ) { if ( n == 2 ) return 4 ; int num = ( ( n / 2 ) + 1 ) ; int max = n % num ; int count = n - max ; return count ; } int main ( ) { int n = 5 ; cout << countPairs ( n ) ; }