Test instructions: A game, a children's shoes in the range of 1~n guess a number, b children's shoes to ask a set, a children's shoes to answer each number in the collection, he guessed whether the number can be divided, b to get a guess by these answers to the number, the minimum number of guesses to guess?
Solution: A number can be multiplied by the exponential Shan of several prime numbers, so the answer to all numbers can be obtained by asking the exponential power of all prime numbers less than N.
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;vector <int> prime;void init () {bool isprime[1005] = {0}; for (int i = 2; I <=, i++) {if (!isprime[i]) {prime.push_back (i); for (int j = i + i; j <=; J + = i) isprime[j] = 1; }}}int Main () {init (); int n; while (~SCANF ("%d", &n)) {vector <int> ans; for (int i = 0; i < prime.size (); i++) {int tmp = Prime[i]; while (TMP <= N) {ans.push_back (TMP); TMP *= Prime[i]; }} cout << ans.size () << Endl; for (int i = 0; I < Ans.size (); i++) {if (i) printf (""); cout << Ans[i]; } puts (""); } return 0;}
CF 577C Vasya and Petya ' s Game