当前位置: 首页 > 工具软件 > SwitchOff > 使用案例 >

【C-算法题】switch off light

经兴安
2023-12-01

#include<stdio.h>
#include<string.h>
#define MAX 1010
int a[MAX];


int main()
{
int n,k,first=1;
memset(a,0,sizeof(a));
scanf("%d%d",&n,&k);
for(int i=1;i<=k;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]) {
if(first)
first=0;
else
printf(" ");
printf("%d",i);
}
printf("\n");
return 0;
}

 类似资料: