zoukankan      html  css  js  c++  java
  • CF F. Kate and imperfection(四月8号)

    F. Kate and imperfection
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Kate has a set SS of nn integers {1,,n}{1,…,n}.

    She thinks that imperfection of a subset MSM⊆S is equal to the maximum of gcd(a,b)gcd(a,b) over all pairs (a,b)(a,b) such that both aa and bb are in MM and aba≠b.

    Kate is a very neat girl and for each k{2,,n}k∈{2,…,n} she wants to find a subset that has the smallest imperfection among all subsets in SS of size kk. There can be more than one subset with the smallest imperfection and the same size, but you don't need to worry about it. Kate wants to find all the subsets herself, but she needs your help to find the smallest possible imperfection for each size kk, will name it IkIk.

    Please, help Kate to find I2I2, I3I3, ..., InIn.

    Input

    The first and only line in the input consists of only one integer nn (2n51052≤n≤5⋅105)  — the size of the given set SS.

    Output

    Output contains only one line that includes n1n−1 integers: I2I2, I3I3, ..., InIn.

    Examples
    input
    Copy
    2
    
    output
    Copy
    1 
    input
    Copy
    3
    
    output
    Copy
    1 1 
    Note

    First sample: answer is 1, because gcd(1,2)=1gcd(1,2)=1.

    Second sample: there are subsets of SS with sizes 2,32,3 with imperfection equal to 1. For example, {2,3}{2,3} and {1,2,3}{1,2,3}.

     题目的大致意思是这样的,输入一个数N然后输出N-1个数,其中每一项都是从1~当前那个数两两相比最小的公倍数;

    (既然是gcd,那么可以通过筛法的思路来写,比如2那么所有2的倍数都标记一下,然后以此类推。。。。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int a[500005];
     4 int main(){
     5     int n;
     6     cin>>n;
     7 for(int i=1;i<=n;i++){//从一开始循环n次 
     8         for(int j=2*i;j<=n;j+=i){//like线性筛一样标记每一个尽可能小的可能出现的共倍数
     9             a[j]=i;
    10         }
    11     }
    12 /*    for(int i=1;i<n;i++){
    13         cout<<a[i]<<" ";
    14     }
    15     cout<<'
    ';
    16 */    sort(a+1,a+n+1);//排一下序
    17     for(int i=2;i<=n;i++){//i==1时a[i]肯定是0 没有gcd所以从2开始到n结束 
    18         cout<<a[i]<<" ";
    19     }
    20     cout<<'
    '; 
    21 
    22 return 0;
    23 }
  • 相关阅读:
    各种概念POJO、JAVABEAN、DAO、DTO、PO、VO、BO、SSH、EJB
    SSH框架与SSI框架的区别
    SSH框架结构分析
    SSH框架系列:Spring配置多个数据源
    Java系列之:看似简单的问题 静态方法和实例化方法的区别
    数据库同步和使用JSONObject让Java Bean“原地满状态复活”
    Java工作队列和线程池
    Lucene之删除索引
    Java设计模式之Iterator模式
    有关《查找两个List中的不同元素》的问题解答与编程实践
  • 原文地址:https://www.cnblogs.com/ahijing/p/12683728.html
Copyright © 2011-2022 走看看