题解 | #K-skipPermutation#
K-skipPermutation
https://ac.nowcoder.com/acm/problem/222763
显然,当枚举的值等于k+1时,结束循环即可
#include <bits stdc++.h> using namespace std; int n,k; const int N = 1e6 + 10; bool st[N]; int main(){ cin >> n >> k; int a = 1; while(1){ if(a == k + 1) break; for(int i=a;i<=n;i+=k){ if(!st[i]) cout << i << " "; st[i] = true; } a++; } for(int i=1;i<=n;i++) if(!st[i]) cout << i << " "; return 0; }