C - Yet Another Array Restoration

先求出最小的整数公差,再求出第一项,最后求整个等差数列

#include <iostream>
using namespace std;
int n,x,y;
int main () {
	int T;
	cin >> T;
	while (T--) {
		cin >> n >> x >> y;
		int t = n-1;
		while (true) {
			if ((y-x)%t == 0) break;
			t--;
		}
		t = (y-x)/t;
		x = max ((x-1)%t+1,y-t*(n-1));
		while (n--) {
			cout << x << ' ';
			x += t;
		}
		cout << endl;
	}
	return 0;
}
posted @ 2022-06-18 09:59  incra  阅读(12)  评论(0)    收藏  举报