简单质数运算,一开始格式错误,哎,然后加了个hash: { Author:wzx961008 Problem:UVa 406-Prime Cuts Verdict:Accepted Language:PASCAL Run Time:0.096s Submission Date:2011-02-03 15:04:49 } uses math; var i,n,c,top,sum,point:longint; stack:array[1..1000]of longint; hash:array[1..1000]of -1..1; function prime(n:longint):boolean; var i:longint; begin if (n=1)or(n=2) then exit(true); for i:=2 to trunc(sqrt(n)) do if n mod i=0 then exit(false); exit(true); end; begin fillchar(hash,sizeof(hash),0); while not eof do begin readln(n,c); top:=0; for i:=1 to n do begin if hash[i]=0 then if prime(i) then hash[i]:=1 else hash[i]:=-1; if hash[i]=1 then begin inc(top); stack[top]:=i; end; end; if top mod 2=0 then begin sum:=min(2*c,top); point:=max(top div 2-c+1,1); end else begin sum:=min(2*c-1,top); point:=max(top div 2-c+2,1); end; write(n,' ',c,':'); repeat dec(sum); write(' ',stack[point]); inc(point); until sum=0; writeln; writeln; end; end.