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

    C. Vasya and Petya's Game

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/577/problem/C

    Description

    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.

    Sample Input

    4

    Sample Output

    3

    2 4 3

    HINT

    题意

    在1-n中随便选一个数,然后你可以提问,问这个数是否%y==0

    问你最少问多少次,可以确定这个数

    题解:

    假设,你没有问p^k(p是素数,k>1),那么你是不能够分辨p^k-1 和p^k的

    所以你就必须问咯

    所以最后答案只需要把小于等于n的素数以及素数的幂都输出出来就好了

    代码:

    //qscqesze
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 500001
    #define mod 1001
    #define eps 1e-9
    #define pi 3.1415926
    int Num;
    //const int inf=0x7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    vector<int> ans;
    vector<int> Q;
    int main()
    {
        int n=read();
        if(n==1)
        {
            printf("0");
            return 0;
        }
        for(int i=2;i<=n;i++)
        {
            int flag = 0;
            for(int j=2;j*j<=i;j++)
            {
                if(i%j)continue;
                flag=1;break;
            }
            if(!flag)ans.push_back(i);
        }
        for(int i=0;i<ans.size();i++)
        {
            int j = ans[i];
            for(;j<=n;j*=ans[i])
                Q.push_back(j);
        }
        printf("%d
    ",Q.size());
        for(int i=0;i<Q.size();i++)
            printf("%d ",Q[i]);
        printf("
    ");
    }
  • 相关阅读:
    025-Cinder服务-->安装并配置一个本地存储节点(ISCSI)
    023-OpenStack 创建实例类型临时磁盘的讲解
    addClass+siblings+removeClass用意:
    SublimeText 改变 tab的距离
    正则表达式选取数值
    正则表达式用来根据某种匹配模式寻找字符串中的某些单词。
    hasOwnProperty()函数
    翻转字符串算法
    输入框禁用和启用
    什么是thinkphp
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4800755.html
Copyright © 2011-2022 走看看