2 条题解

  • 1
    @ 2024-06-08 11:59:37
    #include<iostream>
    #include<cmath>
    using namespace std;
    bool b[100001];
    bool isprime(int i){
        for(int j = 3; j <= sqrt(i); j++){
            if(i % j == 0)return false;
        }
        return true;
    }
    int main(){
        ios::sync_with_stdio(false);
        for(int i = 1; i <= 100001; i++)b[i] = false;
        int n, k;
        cin >> n >> k;
        for(int j = 2; j <= n; j += 2)b[j] = !b[j];
        for(int i = 3; i <= k; i += 2){
            if(isprime(i)){
                for(int j = i; j <= n; j += i)b[j] = !b[j];
            }
        }
        for(int i = 1; i <= n; i++){
            if(b[i])cout << i << " ";
        }
        return 0;
    }
        
    

    可能用数论也能解决,但我数论太辣鸡了(我在讨论里发了)

  • 1

    #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;
    }

  • 1

信息

ID
1113
难度
3
分类
模拟 点击显示
标签
递交数
69
已通过
37
通过率
54%
上传者