xuyux @ 2024-10-08 18:56:20
by xuyux @ 2024-10-08 19:05:26
咋用数组做啊 急急急
by shanxiwen @ 2024-10-08 19:10:58
@xuyux 求关
#include<bits/stdc++.h>
using namespace std;
int n;
bool a[5010]; // 1 表示灯关着, 0 表示开着,初始全为 0
int main(){
cin>>n;
for (int i=1; i<=n; i++){
for (int j=i; j<=n; j+=i){
a[j]=!a[j]; // 如果是 0 ,变成 1; 如果是 1 ,变成 0。
}
}
for (int i=1; i<=n; i++){
if (a[i]==1){
cout<<i<<' ';
}
}
return 0;
}
by xuyux @ 2024-10-08 19:21:52
@shanxiwen 互关吗ლ(′◉❥◉`ლ)? 以关
by shanxiwen @ 2024-10-08 19:23:02
@xuyux 已互关
by wuyusheng @ 2024-10-08 19:25:17
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
bool a[5001];
cin>>n;
memset(a,0,sizeof(a));
for(int i=2; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if(j%i==0)
{
a[j]=!a[j];
}
}
}
for(int i=1; i<=n; i++)
{
if(a[i]==0)
cout<<i<<" ";
}
cout<<endl;
return 0;
}
@xuyux