1, HDU 5976 Detachment
2, test instructions: to a positive integer x, the x is split into multiple positive integers, and these numbers can not be duplicated, to make the product of these numbers as large as possible, output product.
3, Summary: First of all we have to remove the number as small as possible, so that the product will be more large (of course, can not be dismantled 1). So it is easy to think of breaking into 2+3+...+n+s=x, first to find out N is 2+3+...+n<x<2+3+...+n+ (n+1), and then a number to the right to translate s units into n+1 can. Note: (1) preprocessing prefix and prefix product. (2) to move a number to n+1, in addition to this number again multiply n+1, here to use the inverse, also to be preprocessed out.
#include <bits/stdc++.h>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineF (I,A,B) for (int i=a;i<b;i++)#defineFF (I,A,B) for (int i=a;i<=b;i++)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3ftypedefLong Longll;Const intN = 1e5+Ten;Constll mod = 1e9+7;intSum[n],inv[n];ll Mul[n];//int tot;voidinit () {sum[1]=0; mul[1]=inv[1]=1; F (i,2, N) {Sum[i]=i+sum[i-1];//Prefixes andmul[i]=i*mul[i-1]%mod;//Prefix productinv[i]= (mod-mod/i) *inv[mod%i]%mod;//O (N) time to find the inverse, the mod is required to be a prime number//tot=i; }}intMain () {intt,x; scanf ("%d", &T); Init (); while(t--) {scanf ("%d",&x); if(x<5) printf ("%d\n", x); Else { /*int L=lower_bound (sum+1,sum+1+tot,x)-sum; You can directly function two points to find the first position greater than or equal to X if (sum[l]==x) {printf ("%d\n", mul[l]); continue;} l--; */ intL=2, r=n,mid= (l+r) >>1;//Special Note: Two-point notation, mid-first definition, not in the while inside while(L +1<r) {//mid= (l+r) >>1; //Note: At the beginning of this writing, wrong, or develop a habit, first define mid aboveSum[mid]>x? R=mid:l=mid; Mid= (l+r) >>1; } ll ans; intK,num; Num=x-sum[l], k=l+1-num; if(2+NUM>L) ans=mul[l]*inv[2]%mod* (2+num)%MoD; Elseans=mul[l]*inv[k]%mod* (L +1)%MoD; printf ("%lld\n", (ans+mod)%MoD); } } return 0;}
View Code
HDU 5976 Mathematics, inverse element