Click here to Skip to main content
15,795,318 members
Please Sign up or sign in to vote.
1.27/5 (5 votes)
See more:
You are batting at the pitch and all eyes are on you, the best player in all of IPL The opposing team will relentlessly bowl at you an infinite number of balls You notice that you only ever score a boundary on the Mth ball, if N mod M?N/2, where N is the lucky number of your T-shirt. Now you wanna know how many boundaries will you hit in total? Formally, you are given a positive integer N and you need to find the number of positive integers M such that N mod M?N/2.

What I have tried:

#include <iostream>
Using namespace std;
int main() 
int T: 
C in>>T; 
for(int j =0;j<T; j++) 
int N: 
C in>>N; 
Updated 17-Jul-22 1:38am
CHill60 13-Jul-22 4:51am    
What is your question?
Richard MacCutchan 13-Jul-22 4:52am    
What exactly is "N mod M?N/2"? I know N mod M and N / 2, but what does the ? mean in that expression?
Patrice T 13-Jul-22 4:56am    
And you probably have a question and context too.

Im not an expert here I dont understand the question either but
this is my understanding of the statement above..

this will display the numbers from 0 to Mth value where N is the lucky number and M is the number od iterations
then the M modulo N should be equal to the value of (N/2)

the program below will result to
the M = 7
the M = 22
the M = 37
the M = 52
the M = 67
the M = 82
the M = 97
Number of Hits: 7

#include <stdio.h>

int M_limit=100;    //the Mth limit
int N = 15;         //your lucky number N
int H_count=0;      //number positive integers M 

void the_M(){
    for(int a=1; a<M_limit; a++){
         int M=a;
        if( (N%M) ==(N/2)){             //if we reverse M and N in the modulo the program will crash i dont know
            printf("the M = %d\n",a);   //print the M value based from the formula above i think
            H_count++;                  //
    printf("\nNumber of Hits: %d\n",H_count);  //print the number of integers of Ms

int main(){

    return 0;
Share this answer
CPallini 13-Jul-22 9:09am    
"//if we reverse M and N in the modulo the program will crash i dont know"
Because division by 0 is not allowed (as in ordinary math...).
Note that Requirements state: "you need to find the number of positive integers M", so, starting with a=0 doesn't make sense.
bonezegei 13-Jul-22 9:17am    
oh, yeah right. I just realize that now. Thank you

therefore it should be like this,
I tested it just now and it worked..

for(int a=1; a
CPallini 13-Jul-22 9:18am    
You are welcome.
Dave Kreskowiak 13-Jul-22 9:45am    
Doing someones homework for them is not helping them and is never a good idea.
bonezegei 13-Jul-22 10:00am    
yes that's really true. But on the otherside I learned from it.
As this is obviously a far - fetched story and formula based on it, one cannot be sure what the expected solution will be. Maybe the values ​​don't matter at all...
Based on the source code given by the author and the solution formula (N%M) ? (N/2) a solution in C++ could look like this.
cin >> N;
int M_MAX = N * 2; // limit of M
for (int M = 1; M <= M_MAX; M++) {
   if( (N%M) ? (N/2) : 0 > 0) {
      cout << M << ", ";    // print the M value if it fits
      count++;              // count boundaries

// Output for Lucky Number N = 15 would be 2, 4, 6, 7, 8, 9, 10, ...
Number of Hits : 26
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900