利用队列,只有当队列首等于队列尾的时候跳出循环,最后输出队列首的元素
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
queue<int> a;
for (int i = 1; i <= n; i++)
a.push(i);
int b = 1;
while (1) {
if (b % k != 0 && (b - k) % 10 != 0)
a.push(a.front());
a.pop();
if (a.front() == a.back())
break;
b++;
}
cout << a.front() << endl;
return 0;
}