zoukankan      html  css  js  c++  java
  • Codeforces Round #319 (Div. 2) C. Vasya and Petya's Game 数学

    C. Vasya and Petya's Game
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.

    Petya can ask questions like: "Is the unknown number divisible by number y?".

    The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.

    Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.

    Input

    A single line contains number n (1 ≤ n ≤ 103).

    Output

    Print the length of the sequence of questions k (0 ≤ k ≤ n), followed by k numbers — the questions yi (1 ≤ yi ≤ n).

    If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.

    Examples
    input
    4
    output
    3
    2 4 3
    input
    6
    output
    4
    2 4 3 5
    题意:给你一个数n,你给k个数,告诉你整除不整除,用最少的数确定那个数;
    思路:根据唯一分解定理,利用素数和素数的次方即可,详见代码;
    #include<bits/stdc++.h>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define pi (4*atan(1.0))
    const int N=1e2+10,M=1e6+10,inf=1e9+10;
    int prime(int n)
    {
        if(n<=1)
        return 0;
        if(n==2)
        return 1;
        if(n%2==0)
        return 0;
        int k, upperBound=n/2;
        for(k=3; k<=upperBound; k+=2)
        {
            upperBound=n/k;
            if(n%k==0)
                return 0;
        }
        return 1;
    }
    int p[10010],flag;
    int ans[10010];
    int main()
    {
        int x,y,z,i,t;
        flag=0;
        for(i=2;i<1000;i++)
        if(prime(i))
        p[flag++]=i;
        scanf("%d",&x);
        int ji=0;
        for(i=0;i<flag;i++)
        {
            if(x<p[i])break;
            int base=p[i];
            while(x>=base)
            {
                ans[ji++]=base;
                base*=p[i];
            }
        }
        printf("%d
    ",ji);
        for(i=0;i<ji;i++)
        printf("%d ",ans[i]);
        return 0;
    }
  • 相关阅读:
    java算法:树遍历
    java算法:图遍历(深度优先和广度优先)
    Google禁止继续研发开源的"盖亚计划"
    Vc编程调试入门
    访著名Linux内核程序员大鹰
    访著名Linux内核程序员大鹰
    百度玩"精准搜索" 个人隐私保护问题值得商榷
    Google禁止继续研发开源的"盖亚计划"
    加密CMD使电脑溢出也拿不到CMD权限
    百度玩"精准搜索" 个人隐私保护问题值得商榷
  • 原文地址:https://www.cnblogs.com/jhz033/p/5572144.html
Copyright © 2011-2022 走看看