description
For a positive integer, if all the number is less than a divisor of the number are less than the number itself about a number, I think this number is exactly what we want.
Entry
Enter a positive integer X.
Export
X a is not greater than the output of satisfying the above requirements and the maximum number a.
Sample input 1
1000
Sample Output 1
840
prompt
For 10% of the data, 1 <= n <= 1,000. For 40% of the data, 1 <= n <= 1,000,000. To 100% of the data, 1 <= n <= 2,000,000,000.
Code (Why did not write it borrowed ideas teacher code, detailed notes?):
#include <cstdio> #include <the iostream> the using namespace STD; typedef Long Long LL; int Prime [12 is] = {0, 2,. 3,. 5,. 7,. 11, 13 is,. 17,. 19, 23 is, 29}; / / 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29> n, thus taking into account only 29 to LL n-, BestSum, BestNum; // current number of the num go, followed by the first k prime numbers, the number of divisor num SUM, // the upper limit of the number k primes to limit void Solve (num LL, LL SUM, limit LL, LL k) { IF (SUM> BestSum) {// found more divisor of the number, the more stored divisor of the number of natural BestSum = sum; // save the number BestNum = num; // save the number itself } else if (sum == BestSum && num <BestNum) {/ when the same / divisor number, taking the fractional BestNum NUM =; } for (int i =. 1; i <= limit; i ++) {// i th prime number k takes num * = prime [k]; if (num> n) // num more than n , apparently you do not need to go to find return; // second parameter sum * (1 + i) represents the number of the current number of about num, reference is prime decomposition theorem // third parameter is i, the latter represents a number of power can not exceed the number in front of power Solve (num, SUM * (. 1 + I), I, K +. 1); } } int main () { CIN n->>; // Solve (num, SUM, limit, K) // num current went this number is the number of divisor num sum, followed by the first k prime numbers, the upper limit of the number of k primes limit Solve (. 1,. 1, 30,. 1); COUT << BestNum; return 0; }