题目描述
There are N boxes arranged in a circle. The i-th box contains Ai stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation: Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box. Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed. Constraints 1≤N≤10 5 1≤Ai≤10 9
输入
The input is given from Standard Input in the following format: N A1 A2 … AN
输出
If it is possible to remove all the stones from the boxes, print YES. Otherwise, print NO.
样例输入
54 5 1 2 3
样例输出
YES
提示
All the stones can be removed in one operation by selecting the second box.
#include#define ll long longusing namespace std;const int maxn=1e5+10;ll a[maxn];int main(){ ll i,j,k,m,n; cin>>n; ll cnt=0,ans=0,sum=0; for(i=1; i<=n; i++) { cin>>a[i]; sum+=a[i]; } if((2*sum)%(n*(n+1))!=0) { cout<<"NO"<
首先几个数的和一定是1到n的和的倍数
不是则no
根据是几倍判断有多少个1到n
然后找规律