Title: The naïve Factor decomposition
Portal: https://vijos.org/p/1889
Title Description:
Kojima: What is a factorization?
Doc: The given positive integer n is decomposed into the form of a number of prime multiplication.
Kojima: What about n=12, for example?
Doc: so that's 12 = 2 * 2 * 3 yes.
Small island: Wow, good hard, incredibly prime number will be repeated, if the decomposition after each prime number will only appear once, I will.
Wish: In this way, the number of small islands that can be properly decomposed is not many.
Doc: Yes, yes.
Wish: Now the question is, what is the number of the K island that cannot be correctly decomposed for a given k?
Analysis:
(1) It is clear that the subject asks you to find the number of nth mobius[i]==0. Algorithm one: To find out the Mobius function after the answer to ask, you can get 30 points.
(2) Considering the value of the function $f_x=\sum_{i \leq x \&\& mobius[i]==0}1$, it is clear that this function satisfies monotonicity. Algorithm two: Can be two x, ask $f_x$, compare the size of K and $f_x$.
(2.1) How to quickly seek $f_x$? Consider the principle of repulsion. $f _x=\sum_i-mobius[i]*{n \over {i^2}}$. Apparently $i \leq \sqrt{n}$. $mo[i]=mobius[i]$ that is, if there is a square factor, the assignment is 0, otherwise an odd number of factors are assigned a value of 1, an even number is assigned to-1. The Mobius function is obtained by using the linear sieve method.
(2.2) The upper bound of the two points can be tried, here directly to provide: (25505460948).
Code:
1#include <cstdio>2#include <iostream>3 #defineLL Long Long4 ConstLL inf=25505460948ll;5 BOOLv[1000005];6 intp[1000005],mo[1000005];7 voidGetmo () {8 Const intn=1000000;9 for(intI=2; i<=n;++i) {Ten if(!v[i]) {p[++p[0]]=i;mo[i]=1;} One for(intj=1; j<=p[0] && i*p[j]<=n;++j) { Av[i*p[j]]=true; - if(i%p[j]==0) {mo[i*p[j]]=0; Break;} -mo[i*p[j]]=-Mo[i]; the } - } - } - ll Check (ll x) { +LL sum=0; - for(LL i=1; i*i<=x;++i) +sum+=mo[i]*x/(i*i); A returnsum; at } - intMain () { - //freopen ("In.txt", "R", stdin); - Getmo (); -LL k,l=0, r=Inf,mid; -scanf"%lld",&k); in for(; l<=R;) { -Mid= (l+r) >>1; to if(Check (mid) <k) +L=mid+1;Elser=mid-1; - } theprintf"%lld", L); * //fclose (stdin); $ return 0;Panax Notoginseng}
[VIJOS1889] the naïve factor decomposition