计蒜客开关灯

tech2024-06-25  54

int a[5000],m,n; cin >> n>>m; //m盏灯,n个人 for (int i=0;i<=n;++i) a[i] = 1; for(int k = 1; k <= m; ++k) for (int j = 1; j <= n; ++j) { if (j % k == 0) //能够被整除,关灯,0变1,1变0 a[j] = abs(a[j] - 1); } int out_number = 1; for (int t = 1; t <= n; ++t) if (a[t] == 0) { if (out_number == 1) cout << t; else { cout << "," << t; } out_number = 0; }
最新回复(0)