数学知识求序列和
序列和
https://www.nowcoder.com/practice/46eb436eb6564a62b9f972160e1699c9?tab=answerKey
就是等差数列求和,推出a1 = 2N-i(i-1) / 2i即可。
i就是大等于L的长度。a1是第一项。
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int L = sc.nextInt(); boolean flag = false; for(int i = L; i <= 100; i++){ if((2*N + i - i*i) % (2 * i) == 0){ flag = true; int a1 = (2*N + i - i*i) / (2 * i); for(int j = 0; j < i - 1; j++){ int a = a1 + j; System.out.print(a + " "); } System.out.println(a1 + i - 1); break; } } if(!flag){ System.out.println("No"); } } }