Why my logic is not working

thats my code for this problem.

using namespace std;

int main() {
int t;
long n,k;

return 0;


its not necessary always that for k we get the max coins left out for dog.
Like for example ,10 5 so according to your code the dog shall get 0(10%5)coins but if we keep k==4,then the coins the dog will get will be 2(10%4=2)

1 Like

Because you have interpreted the problem statement wrongly, specifically the following statement from the problem:

You can assume that he can choose to call any number of people, from a minimum of 1, to a maximum of K.

However, the problem is simply asking you to find the maximum remainder you can get when you divide N by i where i \in [1, K].

1 Like