题目地址:http://codevs.cn/problem/1053/
分析:
模拟
代码:
var s:string;
a:array['a'..'z'] of longint;
i,j,t,n:longint;
k:char;
d:array[1..100000] of longint;
function cf(x:longint):boolean;
var i,y:longint;
begin
y:=0;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then y:=1;
if (x=1) or (y=1) then cf:=false
else cf:=true;
end;
begin
readln(s);
for i:=1 to length(s) do
a[s[i]]:=a[s[i]]+1;
for k:='a' to 'z' do
if a[k]>0 then
begin
n:=n+1;
d[n]:=a[k];
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if d[i]<d[j] then begin t:=d[i]; d[i]:=d[j]; d[j]:=t; end;
i:=d[1]-d[n];
if (cf(i)) and (i>=1) then begin writeln('Lucky Word');writeln(i); end
else begin writeln('No Answer'); writeln('0'); end;
end.