找很久了,也没问题呀?

B2092 开关灯

zhangjialing1234 @ 2025-01-10 22:27:43

#include <iostream>
using namespace std;
int a[2005];
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        a[i] = 1;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(j % i == 0){
                if(a[i] == 1){
                    a[i] = 0;
                }else if(a[i] == 0){
                    a[i] == 1;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if(a[i] == 0){
            cout << i << " ";
        }
    }
    return 0;
}

by 迟暮天复明 @ 2025-01-10 22:49:16

else if(a[i] == 0){
    a[i] == 1;
}

|