Problem DescriptionMother bought n pieces of sugar for little b. But she doesn't allow little b to eat directly.
Assuming that there is an M-block sugar, a small B can take a P-block sugar at a time, where p is a mass factor of m less than the root. At this time, the mother will be in small B take the p block sugar and then from the sugar heap to take the p block sugar. Then little b can take the sugar.
Now little B wants to know how much sugar you can get.
Input FormatAn integer n
output FormatHow much sugar can you take?
Sample Input15
Sample Output6
Data size and ConventionN <= 100000
Import java.util.ArrayList;
Import java.util.List;
Import Java.util.Scanner;
public class Main {private static list<integer> prime = new arraylist<> ();
public static void Main (string[] args) {Scanner in = new Scanner (system.in);
int n = in.nextint ();
In.close ();
Setprime (n);
Int[] dp = new Int[n + 1]; for (int i = 0; i < prime.size (); i++) {for (int j = 1; J <= N; j +) {if (j% prime.get (i) = 0 && (J >= 2 * prime.get (i)))
{Dp[j] = Integer.max (Dp[j], dp[j-2 * Prime.get (i)] + prime.get (i));
}} System.out.println (Dp[n]);
} private static void Setprime (int n) {boolean[] p = new Boolean[n + 1];
for (int i = 2; i < p.length i++) {P[i] = true;
for (int i = 2; i < P.length. i++) {for (int j = 2; I * J < P.length; J +) {P[i * j] = false;
for (int i = 2; I * I <= n; i++) {if (p[i)) {prime.add (i); }
}
}
}