type arr=array[1..10] of boolean;
var n,p,q,i:longint; s:string;
a:array[0..10000] of longint;
b:arr;
function judge(j:longint):boolean;
var i:longint;
begin
judge:=false;
for i:=p+1 to q-1 do
if j mod i=0 then begin judge:=true; break; end;
end;
procedure dfs(x:longint;ss:string;b:arr);
var i,j:longint;
begin
ss:=ss+s[x]; b[x]:=false;
for i:=1 to length(s) do
if b[i] then dfs(i,ss,b);
if length(ss)=length(s) then
begin
val(ss,j);
if judge(j) then
begin inc(a[0]); a[a[0]]:=j; end;
end;
end;
procedure print;
var i,j,t:longint;
begin
for i:=1 to a[0]-1 do
for j:=1 to a[0]-i do
if a[j]>a[j+1] then
begin t:=a[j]; a[j]:=a[j z+1]; a[j+1]:=t; end;
for i:=1 to a[0] do writeln(a[i]);
end;
begin
readln(n); str(n,s); a[0]:=0;
readln(p,q);
if p>q then
begin i:=p; p:=q; q:=i; end;
for i:=1 to length(s) do
begin
fillchar(b,sizeof(b),true);
dfs(i,’’,b);
end;
if a[0]=0 then writeln(’No answer’) else print;
end.
另外,你只悬赏三分还指望有大牛帮你看啊.......
^_^
for i:=p+1 to q-1 do
if j mod i=0 then begin judge:=true; break; end;
你不觉得这个循环很耗时吗?
最好在读入P,Q后立刻算出P-Q的最小公倍数u,然后再看每个
j mod u =0 or <>0 就可以了