Đề bài: http://vn.spoj.com/problems/CTNOWN/
Thuật toán:
- (đang cập nhập)
Code:
uses math; const fi=''; fo=''; maxn=350; var n,i,j :longint; dem :longint; nto :array[1..maxn] of longint; cx :array[1..maxn] of boolean; f :array[0..maxn,0..maxn] of qword; t,tt,k :longint; res,tam :qword; procedure sangnto; var i,j :longint; begin for i:=2 to trunc(sqrt(maxn)) do if cx[i]=false then begin j := i*i; while (j<=maxn) do begin cx[j]:=true; j := j+i; end; end; for i:=2 to maxn do if cx[i]=false then begin inc(dem); nto[dem] := i; end; end; function max(x,y : qword) : qword; var tg : qword; begin if x>y then exit(x) else exit(y); end; procedure main; begin assign(input,fi);reset(input); assign(output,fo);rewrite(output); sangnto; read(t); for i:=0 to dem do for j:=0 to maxn do f[i,j] := 1; for i:=1 to dem do begin for j:=1 to maxn do begin f[i,j] := f[i-1,j]; tam:=1; while tam*nto[i]<=j do begin tam := tam * nto[i]; f[i,j] := max(f[i,j], f[i-1,j-tam]*tam ); end; end; end; for tt := 1 to t do begin read(n); writeln(f[dem,n]); end; close(input);close(output); end; procedure __; begin end; begin __ ; main; __ ; end. |
Speak Your Mind