DescriptionAntonio has recently been interested in organic chemistry, and he wants to ask you to help him quickly figure out the same differentiation of a certain type of hydrocarbon.the number of construction bodies. for ease of presentation, we define the following:Cycloalkanes: A cycloalkanes with n carbon atoms can be represented as an undirected connection with n edges of n verticessimple Diagram (base ring + outward tree). The degree of each vertex does not exceed 4. M- Cycloalkanes: At most, there are cycloalkanes of M vertices on the ring. (Note that there are at least 3 vertices on the ring becauseThere can be a maximum of 1 edges between any two vertices). isomorphism: Assume that both structure A and structure B have n carbon atoms, A and b isomorphic when and only if it is possible to a andeach carbon atom in B is numbered according to 1~n, so that for the two carbon atoms numbered V1 and v2, heThey are connected in the presence of edges in a and only if they exist in B. (In other words, A and B correspond to the figureisomorphic). now, given N, M,antonio wants you to help him count the number of non-homogeneous, n-carbon atoms.M-Cycloalkanes. Since this number can be large, you only need to output its remainder on p. (P is a prime number). In the subject , we do not consider whether a structure can be chemically stable, or other heterogeneous ways. Input
The input file is only one line, separated by a space of three integers n, m, p. Guaranteed to have M <=n,p as prime number.
OutputThe output file has only one row, representing the number of non-isomorphic m-cycloalkanes with n carbon atoms, pRemainder. First processing out the root of the degree of 2, the remaining point <=4 of the number of non-labeled root tree Ring has rotation and flip two kinds of transformations, due to m>=3, composed of permutation group order of 2m, with Burnside lemma processing rotation K (0<=k<m) Step can form gcd (m,k) Equivalence class, each equivalence class contains M/GCD (m,k) position rotation + rollover needs to be divided into odd-even processing: if M is odd, then there is m this permutation, forming (m+1)/2 equivalence class, where an equivalence class contains a position, the remainder contains 2 positions if M is an even number M/2 permutation formation m/ 2 equivalence classes, each equivalent class contains 2 locations and another M/2 permutation forms m/2+1 equivalence classes, where two equivalence classes contain a position and the remainder contains 2 positions
#include <cstdio>typedef unsignedLong Longu64;typedef unsignedintu32;intn,m;u32 P;intgcdintAintb) { for(intc;b;c=a,a=b,b=c%b); returnA;}intPhiintN) { intv=N; for(intI=2; i*i<=n;++i)if(n%i==0){ DoN/=i; while(n%i==0); V=v/i* (I-1); } if(n>1) v=v/n* (n1); returnv;} Inline u32 Fix (inta) { returnA + (a>> to&P);}structnum{u32 x; Num (u32 a=0): X (a) {} numoperator+ (num w) {returnFix (x+w.x-P);} Numoperator* (num W) {returnU64 (x) *w.x%P;} void operator+ = (num w) {X=fix (x+w.x-P);}}; Num s[5][1007],gs[ One],iv[117],f0[ $][1007],f1[ $][1007],ans;voidCalintMintN) { intg=gcd (n,m); Num v=0; for(intD=1;d <=g;++d)if(g%d==0) v+=f0[m/d][n/d]*Phi (d); V+=f1[m][n]*m;//printf ("%d,%d:%d\n", m,n,v*iv[m*2]);ans+=v*iv[m*2];}intMain () {scanf ("%d%d%u",&n,&m,&P); if(m>n) m=N; s[0][0]=iv[1]=1; for(intI=2; i<= the; ++i) iv[i]=iv[p%i]* (p-p/i); for(intI=1; i<=n;++i) {f0[1][i]=f1[1][i]=s[0][i-1]+s[1][i-1]+s[2][i-1]; gs[1]=f0[1][i]+s[3][i-1];//printf ("[%d:%d]\n", i,gs[1]); for(intj=2; j<=3; ++j) gs[j]=gs[j-1]* (gs[1]+ (J-1))*Iv[j]; for(intj=3; j;--j) { for(intk=n;k>=i;--k) { for(intt=1; t<=j;++t) { intw=k-t*i; if(w>=0) s[j][k]+=gs[t]*s[j-T] [W]; } } } } for(intI=2; i<=m;++i) { for(intj=i;j<=n;++j) { for(intk=1; k<j;++k) f0[i][j]+=f0[i-1][j-k]*f0[1][k]; if(i&1){ for(intk=2; k<j;k+=2) f1[i][j]+=f0[i>>1][k>>1]*f0[1][j-K]; }Else{ for(intk=1; k<j;++k) f1[i][j]+=f1[i-1][j-k]*f0[1][k]; if(~j&1) f1[i][j]+=f0[i>>1][j>>1]; F1[I][J]=f1[i][j]*iv[2]; }//printf ("%d,%d%d%d\n", i,j,f0[i][j],f1[i][j]); } } for(intI=3; i<=m;++i) Cal (I,n); printf ("%d\n", ans.x); return 0;}
Bzoj 2601: [Jsoi2011] isomer count