Count numbers less than N whose modulo with A is equal to B | C ++ program for the above approach ; Function to count numbers less than N , whose modulo with A gives B ; If the value of B at least A ; If the value of B is 0 or not ; Stores the resultant count of numbers less than N ; Update the value of ans ; Print the value of ans ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countValues ( int A , int B , int C ) { if ( B >= A ) { cout << 0 ; return ; } if ( B == 0 ) { cout << C / A ; return ; } int ans = C / A ; if ( ans * A + B <= C ) { ans ++ ; } cout << ans ; } int main ( ) { int A = 6 , B = 3 , N = 15 ; countValues ( A , B , N ) ; return 0 ; }