zoukankan      html  css  js  c++  java
  • [CF1333F] Kate and imperfection

    Description

    集合 (S = {1,2,...,n}) 的一个子集 (M) 的不完美值等于 (max_{a,bin M} gcd(a,b))(a eq b),对于 (k =2,3,...,n),求满足 (|M|=k) 的所有 (M) 中不完美值的最小值。

    Solution

    对于一个子集,如果 (a,b in M)(a mod b equiv 0),则删去 (a) 一定比删去 (b)

    于是,若 (a) 在数列中,则 (a) 的所有约数一定在数列中,于是 ((a,b)=c)(c) 一定存在

    于是一个子集的答案就是其中所有数的最大真因子的最大值

    直接 (O(nlog n)) 暴力预处理最大真因子,排序输出即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 500005;
    
    int n,m,t,a[N];
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            for(int j=i+i;j<=n;j+=i)
            {
                a[j]=i;
            }
        }
        sort(a+1,a+n+1);
        for(int i=2;i<=n;i++)
        {
            cout<<a[i]<<" ";
        }
    }
    
    
  • 相关阅读:
    TCP 连接中的TIME_WAIT
    tcp 重组原理
    自己用wireshark 抓了个包,分析了一下
    wireshark 使用技巧
    IP 网际协议
    CSS3 选择器
    ajax 底层源码解析
    初识 Java
    jQuery (DOM篇)
    绘制 SVG
  • 原文地址:https://www.cnblogs.com/mollnn/p/13620734.html
Copyright © 2011-2022 走看看