Home > Back-end >  C language oj monkeys choose big king, why the wrong T ^ T
C language oj monkeys choose big king, why the wrong T ^ T

Time:12-15

The Monkey King, method is as follows: the monkey press 1, 2... N number around a circle, from the first only press 1, 2,... M number off, m's exit, starting from next only, continue to cycle count off, the rest of the last monkey is the king of judah, the serial number of the great king, the king programming output

Input

Input only a line, the monkey number n and number off m,

The Output

The serial number of the great king, the king output only a line, output

The Sample Input

10 3
The Sample Output

4





#include
Int main ()
{
Long long int n, m, I, a [1000], the sum=0, nn, * p;
The scanf (" % LLD % LLD, & amp; N, & amp; M);
Nn=n;
for(i=0; iA [I]=1;

If (n==1)
Printf (" % LLD \ n ", n);
The else
{
While (n!
=1){
for(i=0; i{
If (a [I]==1)
{
sum++;

}
If (sum % m==0)
{
N -;

A [I]=0;
}

If (n==1)
break;

}


}


for(i=0; i{
If (a [I]==1)
break;

}
Printf (" % LLD \ n ", I + 1); }
return 0;
}



Bosses help me have a look at what is wrong? Wa T ^ T
  • Related