数学推导

alt

#include<bits/stdc++.h>
using namespace std;
const int M=4e4+5;
typedef long long ll;
ll b[M];
ll a[M];
void sove(){
	int n; cin>>n;
	ll sum=0; ll m=(1+n)*n/2;
	for(int i=1;i<=n;i++){
		ll x; cin>>x;
		b[i]=x;
		sum+=x;
	}
	if(sum%m!=0||sum/m<n){
		cout<<"NO"<<'\n';
	    return ;
	}
	m=sum/m;
	for(int i=1;i<=n;i++){
		a[i%n+1]=(m+b[i]-b[i%n+1])/n;
		if((m+b[i]-b[i%n+1])%n!=0||a[i%n+1]>1e9||a[i%n+1]<1){
			cout<<"NO"<<'\n';
			return;
		}
	}
	cout<<"YES"<<'\n';
	for(int i=1;i<=n;i++) cout<<a[i]<<" ";
	cout<<'\n';
	return;
	
}
int main(){
	int t; cin>>t;
	while(t--){
		sove();
	}
	return 0;
}