Test instructions
There is a ring sequence, which can be cut into a sequential K-series, then the GCD (and the sequence of each satin) is graceful. Outputs n integers representing the maximum degree of elegance when k=[1, N].
Ideas:
Observe, when cut into 1 paragraphs, GCD is sum[the whole sequence], for maximum. Consider cutting into 2 segments, so it's best to cut the ring into 2 segments and]/2 the entire sequence of sum[. Consider cutting into 3 segments, so it's best to cut the ring into 3 segments and]/3 the entire sequence of sum[. To continue, is this not the approximate sum[of the whole sequence?
Assume that there are k, from the big to the small, respectively, Factor[1~r]. Then some of these factors may not be the group, you have to remove those groups can not be. Assuming that the sum[entire sequence] can be cut into CNT and factor[t] continuous sub-sequence, then the number of i<=cnt, the answer is Factor[t], take the maximum.
The question is how to find out the maximum number of segments that grow to Factor[t] cnt[t]? The current prefix and pre%factor=r appear m times should be this: ... | xxxx|xxxx|......| Xxx|xxxx|. (a total of M incisions |), observed that except for the end and end, each paragraph is a multiple of D, and the sum of the end and end is a multiple of D (because sum[the entire sequence]=k*d). So for Factor[t], you only need to enumerate R to find the maximum m.
1#include <bits/stdc++.h>2 #definePII pair<int,int>3 #defineINF 0x3f3f3f3f4 #defineLL Long Long5 using namespacestd;6 Const intn= .;7Vector<ll>factor, CNT;8 LL A[n];9Map<ll,ll>Mapp;Ten intMain () One { AFreopen ("Input.txt","R", stdin); - intN; - while(~SCANF ("%d",&N)) the { - for(intI=1; i<=n; i++) - { -scanf"%lld",&a[i]); +a[i]+=a[i-1]; - } + for(LL i=1; i*i<=a[n]; i++) A { at if(a[n]%i==0) - { -Factor.push_back (a[n]/i); -Factor.push_back (i);//One more does not affect the result - } - } in sort (Factor.begin (), Factor.end ()); -Deque<ll>ans; to for(intK=factor.size ()-1, i=1; k>=0; k--) + { -LL big=0, c=Factor[k]; the mapp.clear (); * for(intj=1; j<=n; J + +) $Big=max (big,++mapp[a[j]%c]);Panax Notoginseng while(i<=n&&big>=i) - { the Ans.push_back (c); +i++; A } the } + while(!ans.empty ()) - { $printf"%lld\n", Ans.front ()); $ Ans.pop_front (); - } - } the return 0; -}
AC Code
Hihocoder #1246: Wang Yaohao and Ring (math)