#include #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; bool is_win(int n, int k){ return (n - 1) % (k + 1) != 0; // 先攻が勝つ true 後攻が勝つ false } int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; int a, b; int remain = n; bool battle_first = true; // 先攻 if (!is_win(n,k)){ cout << 0 << endl; cin >> b; remain -= b; battle_first = false;// 後攻 } // end if while (1){ int in = 0; for (int i = k; i >= 1; --i){ if ((battle_first && is_win(remain, i)) || (!battle_first && !is_win(remain, i))){ in = i; break; } // end if } // end for a = in + (n - remain); cout << a << endl; cin >> b; if (b >= n) break; remain = n - b; } // end while return 0; }