'commit'
This commit is contained in:
36
TangDou/XiTi/1074.cpp
Normal file
36
TangDou/XiTi/1074.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int N, M;
|
||||
cin >> N >> M;
|
||||
int a[5001] = {0};
|
||||
//全部开启N盏灯
|
||||
for (int i = 1; i <= N; ++i) {
|
||||
a[i] = 1;
|
||||
}
|
||||
//模拟每一个人
|
||||
for (int i = 1; i <= M; ++i) {
|
||||
for (int j = 1; j <= N; ++j) {
|
||||
if (j % i == 0) {
|
||||
a[j] = abs(a[j] - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//输出
|
||||
string result = "";
|
||||
for (int i = 1; i <= N; ++i) {
|
||||
if (a[i] == 0) {
|
||||
//数字转字符串
|
||||
stringstream ss;
|
||||
ss << i;
|
||||
string str = ss.str();
|
||||
//拼接结果
|
||||
result += str + ",";
|
||||
}
|
||||
}
|
||||
if (result.length() > 0) result = result.substr(0, result.length() - 1);
|
||||
cout << result << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user