1053: [HAOI2007] anti-prime ant Time limit:10 Sec Memory limit:162 MB
submit:1907 solved:1069
[Submit] [Status] [Discuss] Description
For any positive integer x, the number of its approximate numbers is recorded as g (x). For example G (1) =1, g (6) = 4.
If a positive integer x satisfies: g (x) >g (i) 0<i<x, it is said that X is an inverse prime number. For example, integer 1,2,4,6, etc. are all anti-prime.
Now given a number n, can you find the largest anti-prime that does not exceed n?
Input
A number N (1<=n<=2,000,000,000).
Output
The maximum number of anti-prime numbers not exceeding N.
Sample Input +Sample Output840HINT Source [Submit][status][discuss]" The Puzzle"First, you can use the combination of mathematical proof, if a number
n=a1x1
xa2x2x ... x akxk So, set the function
Ex-phi (n) to indicate the number of approximate numbers of
n can deduce
ex-phi (n) = (x1+1)(x2+1) ... (xk+1) ....... ..... (It's just a formula, I'm not going to prove it)
The above conclusion is called Theorem 1===========================================It can be calculated that when n is less than 2000000000, there is a maximum of 10 element factorsProof: 2*3*5*7*11*13*17*19*23*29≈60e>20e
The above conclusion is called Theorem 2===========================================It's better to have more factors than major factors .The Ex-phi (n) is certainly larger than the major factor, which is more than the total factor.
The above conclusion is called Theorem 3===========================================However, after the introduction of these magical conclusions, we found that--we maintain the monotonically decreasing of the element factor from small to large quantity. code is not too understood,,,, I added a lot of comments
1#include <bits/stdc++.h>2 using namespacestd;3 Long Longprime[ -]={0,2,3,5,7, One, -, -, +, at, in, to,Panax Notoginseng};4 Long LongAns,num,n;5 //num= the smallest number in the current number (limited language ability ...) ans= the number of approximate numbers at present6InlinevoidDfsintNowLong LongProductLong LongCsLong LongLastcs,Long LongRes)7 //The current number of subscripts current product The number of occurrences of an occurrence number8 {9 if(Ans==res* (cs+1) &&product<num)//The number of the current product is about a number that is already equal to ans and smaller than numTenNum=product;//Update Answer One if(Res* (cs+1) {>ans) {//No, it's definitely updated. AAns=res* (cs+1); -num=product; - } the if(cs+1<=lastcs&&product*prime[now]<=n)//the exponent of each prime number is guaranteed to be monotonic and not exceed N -DFS (now,product*prime[now],cs+1, lastcs,res); - - for(inti=now+1; i<=Ten; i++)//The number of prime numbers used within the data range will not exceed ten + if(product*prime[i]<=n)//Note cannot exceed N -DFS (I,product*prime[i),1, Cs,res* (cs+1)); + } A atInlinevoidGo () - { -Dfs1,1,0, -,1); -printf"%lld\n", num); - } - in intMain () - { toscanf"%lld",&n); + go (); - return 0; the}
[HAOI2007] anti-prime ant