维护 表示现在准备输出的数, 表示已经输出的数的个数,初始 , ,如果 ,就输出,然后 ,不管输不输出 ,一直循环直到 。
#include <bits/stdc++.h>
using namespace std ;
long long n , d , cnt , now = 1 ;
int main() {
cin >> n >> d ;
while(cnt < n) {
if(now % d) {
cnt ++ ;
cout << now << "\n" ;
}
now ++ ;
}
return 0 ;
}
- 时间复杂度: 。
- 空间复杂度: 。
暂无评论