输入描述:
输入数据包括一行:
两个正整数N(1 ≤ N ≤ 1000000000),L(2 ≤ L ≤ 100)
输出描述:
从小到大输出这段连续非负整数,以空格分隔,行末无空格。如果没有这样的序列或者找出的序列长度大于100,则输出No
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;
int l = 1,r = 1;
for(int len=L; len<=100 && !flag; len++) {
// 长度为L的连续整数和N为:设开始整数x,(x+x+L-1)*L/2 = N
int x = (2*N+len*(1-len)) % (2*len);
if ( (x == 0 ) && (2*N+len*(1-len))>=0 ){
flag = true;
l = (2*N+len*(1-len)) / (2*len);
r = l+len-1;
}
}
if(flag) {
for (int i = l; i <= r; i++) {
if (i != r)
System.out.print(i + " ");
else
System.out.print(i);
}
}else {
System.out.println("No");
}
}
}