描述 | |
---|---|
知识点 | 循环 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入一个int整数 |
输出 | 输出分解后的string |
样例输入 | 6 |
样例输出 | 31+33+35+37+39+41 |
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
sc.close();
int n = input * input * input;
System.out.println(getString(n, input));
}
private static String getString(int n, int input) {
//用flag记录字符串的初试数字
int flag = 0;
outer:
for (int i = 1; i <= n; i++) {
int temp = i;
int sum = 0;
flag = temp;
for (int j = 0; j < input; j++) {
sum += temp;
if (sum == n) {
break outer;
}
temp += 2;
}
}
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < input; i++) {
if (i < input - 1) {
stringBuffer.append(flag).append("+");
flag += 2;
}
}
stringBuffer.append(flag);
return stringBuffer.toString();
}
}