fork download
  1. #include <iostream>
  2. using namespace std;
  3. int func(int n,int m) {
  4. int Q[100] ;
  5. int tail = 0 ;
  6. for (int i = 1; i <= n; i++ ) {
  7. Q[ tail ] = i ;
  8. tail = tail + 1;
  9. }
  10. int count = 0 ;
  11. int head = -1 ;
  12. while ( head+1 < tail ) {
  13. count = count + 1 ;
  14. head = head + 1 ;
  15. if ( count == m ) {
  16. count = 0 ;
  17. Q[ tail ] = Q[ head ] ;
  18. tail = tail + 1 ;
  19. }
  20. }
  21. return Q[head] ;
  22. }
  23.  
  24. int main( ) {
  25. printf("%d", func(30, 4) ) ;
  26. }
  27.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
24