bzoj 1025 DP
这道题根据群论的基础知识,我们可以转化成将n拆分成若干数,求这些数
的lcm的方案数
先筛下素数表prime
那么我们可以用DP来解决这个问题,用W[I,J]代表I这个数,拆成若干个数,
其中质因数最大的不超过prime[j]的方案数
那么我们可以得到转移W[I,J]:=W[I,J-1]+ΣW[I-prime[j]^k,j-1] (I>=prime[j])
/************************************************************** Problem: 1025 User: BLADEVIL Language: Pascal Result: Accepted Time:44 ms Memory:8220 kb ****************************************************************/ //By BLADEVIL var prime :array[0..1010] of longint; mindiv :array[0..1010] of longint; i, j :longint; n :longint; w :array[0..1010,0..1010] of int64; cur :longint; begin read(n); for i:=2 to n do begin if mindiv[i]=0 then begin inc(prime[0]); prime[prime[0]]:=i; mindiv[i]:=i; end; for j:=1 to prime[0] do begin if prime[j]*i>n then break; mindiv[prime[j]*i]:=prime[j]; if i mod prime[j]=0 then break; end; end; for i:=0 to n do w[i,0]:=1; for i:=1 to prime[0] do w[0,i]:=1; for j:=1 to prime[0] do for i:=1 to n do begin w[i,j]:=w[i,j-1]; cur:=prime[j]; while i-cur>=0 do begin w[i,j]:=w[i,j]+w[i-cur,j-1]; cur:=cur*prime[j]; end; end; writeln(w[n,prime[0]]); end.