5 条题解
-
1端木俁 (房佳坤) LV 10 @ 2022-07-27 22:00:48
\({\color{Purple} \underline{\mathbf{{\Large 模拟题}}}}\)
\({\color{Purple} \underline{\mathbf{{\Large 严谨一点的话,时间复杂度应该是 \omega (n) ?}}}}\)
#include <cstdio> #include <bitset> #define re register using namespace std; const int N = 1e5 + 10; bitset<N> state; // 0 蹲 int n, k; inline auto isprime(int n) -> bool; auto main(void) -> int { scanf("%d%d", &n, &k); for (re int i = 2; i <= k; i ++ ) { if (isprime(i)) for (re int m = 1; m * i <= n; m ++ ) state.flip(m * i); } for (re int i = 1; i <= n; i ++ ) if (state[i]) printf("%d ", i); return 0; } inline auto isprime(int n) -> bool { if (n <= 3) return n >= 2; for (re int i = 2; i <= n / i; i ++ ) if (!(n % i)) return false; return true; }
-
02022-07-27 16:06:38@
//可以改进的话请各位大神指教
#include <bits/stdc++.h>
using namespace std;
int a[100010]={0};
bool Issushu(int i);
int main()
{
int n;
int k;
int i=2;
scanf("%d%d",&n,&k);
while( i<=k )
{
if(Issushu(i))
{
for(int j=1; j<=n; j++)
if(j%i==0)
a[j]=!a[j];
}
i++;
}
for(int j=1; j<=n; j++)
if(a[j]==1)
printf("%d ",j);
return 0;
}
bool Issushu(int i)
{
int j=2;
while(j<i)
{
if(i%j==0)
break;
j++;
}
if(i==j)
return true;
return false;
} -
02021-05-14 20:23:20@
//有些麻烦了,不过也是一种可以解决的方法。
#include<iostream>
using namespace std;
int is_prime(int n)
{
for (int i = 2; i < n; i++)
{
if (n%i == 0)
{
return 0;
break;
}
}
return 1;
}
int main()
{
int number_class;
int k;
int t;
int a[100000];
for (int x = 0; x < 100000; x++)
{
a[x] = 1;
}
cin >> number_class>>k;
for (int i = 2; i <= k; i++)
{
if (is_prime(i))
{
for (int j = 1; j <= number_class; j++)
{
if (0==j%i)
{
t = -a[j];
a[j] = t;
}
}
}
}
for (int l = 1; l <= number_class; l++)
{
if (a[l] == -1)
{
cout << l;
cout << " ";
}
}
return 0;
} -
-22019-04-27 21:33:21@
//#include"stdafx.h"
#include <iostream>
#include<cstdio>
using namespace std;int a[100010]={0};
bool Issushu(int i);int main()
{
int n;//灯的数量
int k;//人数
int i=2;
scanf("%d%d",&n,&k);
while( i<=k )
{
if(Issushu(i))
{
for(int j=1; j<=n; j++)//将每盏灯都遍历一遍
if(j%i==0)//灯数是素数的倍数
a[j]=!a[j];
}
i++;
}
for(int j=1; j<=n; j++)
if(a[j]==1)
printf("%d ",j);
//printf("\b");
return 0;
}
bool Issushu(int i)
{
int j=2;
while(j<i)
{
if(i%j==0)
break;
j++;
}
if(i==j)
return true;
return false;
} -
-32021-01-24 19:48:37@
#include <bits/stdc++.h>
using namespace std;
int a[100000],n,k; //0为蹲,1为站
void c(int x) {a[x]?a[x]=0:a[x]=1;}
int ss(int x)
{
for(int i=2;i*i<=x;i++) if(x%i==0) return 0;
return 1;
}
int main()
{
int i,j;
cin>>n>>k;
for(i=2;i<=k;i++) if(ss(i)) for(j=1;j<=n;j++) if(j%i==0) c(j);
for(i=1;i<=n;i++) if(a[i]) cout<<i<<" ";
return 0;
}
- 1