分析一波
整数成绩最大化
http://www.nowcoder.com/questionTerminal/3e74c3b36fc442db8fdce3057fb1b5b1
import java.util.Scanner; public class T_test { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int sum = 1; // 多分解几个数就会发现,全分解为2或者3时,乘积最大 if (n <= 0) { System.out.print(0); } else if (n > 0 && n <= 2) { System.out.print(1); } else if (n == 3) { System.out.print(3); } else if (n == 4) { System.out.print(4); } else { while (n > 4) { sum *= 3; n = n - 3; } // 这时n的值可能为2,3,4 if (n >= 2) sum *= n; System.out.print(sum); } } }