#P1734. Maximizing Sum of Proper Divisors Under a Sum Constraint

    ID: 15019 Type: Default 1000ms 256MiB

Maximizing Sum of Proper Divisors Under a Sum Constraint

Maximizing Sum of Proper Divisors Under a Sum Constraint

You are given a positive integer S. Your task is to select several different positive integers such that the total sum of the selected numbers does not exceed S and the sum of all of their proper divisors is maximized. Note that the proper divisors of a positive integer n are all positive divisors less than n. In mathematical terms, for a chosen number n, define its proper divisor sum as:

\( f(n)=\sum_{d|n,\; d<n} d \)

You need to choose a set \(\{n_1,n_2,\dots, n_k\}\) (all distinct) such that \(n_1+n_2+\cdots+n_k \le S\) and the value \(f(n_1)+f(n_2)+\cdots+f(n_k)\) is maximized. Output the maximum achievable sum of proper divisors.

inputFormat

The input consists of a single positive integer S (S ≥ 1) on one line.

Input Format:
S

outputFormat

Output a single integer representing the maximum sum of proper divisors obtainable.

sample

1
0