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 }
  • 相关阅读:
    000IntelliJ IDEA字体大小设置 超级菜鸟
    Zend_Captcha_Image使用及部分功能重写 基于zend Framework 1.6
    人民币存贷款基准利率调整表20110707
    PHP 取得某天前后N天的日期
    jquery 实现 鼠标拖拽元素复制并写入效果
    使用 JScript 创建 .exe 或 .dll 文件
    js window.location
    jquery 中的 $("#air") 与 document.getElementById("air") 的区别
    jquery 查找 iframe 父级页面元素
    php 批量替换文件名
  • 原文地址:https://www.cnblogs.com/ahijing/p/12683728.html
Copyright © 2011-2022 走看看