3 条题解
-
1
#include<bits/stdc++.h> #define MAXN 5001 using namespace std; int a[MAXN]; int main() { int n,m; memset(a,0,sizeof(a)); //作用是把数组a清零 cin>>n>>m; for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ if(j%i==0){ a[j]=!a[j]; //给a[j]赋与其相反的真假值,例如,如果a[j] = 5, 那这个赋值后a[j] = 0如果a[j]=0,赋值语句后a[j]=1 } } } if(a[1]){ cout<<1; } for(int i=2;i<=n;++i){ if(a[i]){ cout<<","<<i; } } cout<<endl; return 0; }
-
1
C++ :
#include<bits/stdc++.h> using namespace std; int main() { int n,m,cnt=0,is_first=1; cin>>n>>m; //灯初始开启 //找关闭的灯 for(int i=1;i<=n;i++) { cnt=0; for(int j=1;j<=m;j++) { if(i%j==0) { cnt++; } } if(cnt%2!=0) { if(is_first) { is_first=0; } else { cout<<","; } cout<<i; } } return 0; }
- 1
信息
- ID
- 501
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 43
- 已通过
- 7
- 上传者