题目
一个自然数是素数,且它的数字位置经过任意对换后仍为素数,则称为绝对素数,例如13.
请找出所有x位的绝对素数的数量.
输入x(x<=5)
输入样例:
1
输出样例:
4
请找出所有x位的绝对素数的数量.
输入x(x<=5)
输入样例:
1
输出样例:
4
提问时间:2021-01-17
答案
var
a,k,i,w,sum,x:longint;
s:array[1..8363]of longint;
e:array[1..8363]of boolean;
st:string;
b:array[1..5]of char;
flag:array[0..9]of boolean;
c:array[1..120]of string;
procedure search(depth:integer);
var i,t:integer;
begin
if(depth>a) then
begin
inc(x);
for i:=1 to a do c[x]:=c[x]+b[i];
exit;
end;
for i:=1 to a do
if flag[i]=false then
begin
b[depth]:=st[i];
flag[i]:=true;
search(depth+1);
flag[i]:=false;
end;
end;
function erfen(o:string):boolean;
var
m,head,tail,j:longint;
begin
val(o,m);
head:=1;
tail:=w;
j:=trunc((head+tail)/2);
repeat
if s[j]=m then exit(false)
else
if s[j]>m then
begin tail:=j-1; j:=trunc((head+tail)/2) end
else if s[j] begin head:=j+1; j:=trunc((head+tail)/2) end;
until (head>tail);
exit(true);
end;
procedure checks(w:longint);
var
i,j:longint;
begin
for i:=1 to w do
begin
str(s[i],st);
x:=0;
search(1);
for j:=1 to k do
if erfen(c[j]) then e[i]:=false;
for j:=1 to k do
c[j]:=';
end;
end;
function check(w:longint):boolean;
var
i:longint;
begin
for i:=2 to round(sqrt(w)) do
if w mod i =0 then exit(false);
exit(true);
end;
procedure trys(a:longint);
var
i,j,head,tail:longint;
begin
tail:=9;
head:=1;
w:=0;
for i:=1 to a-1 do
begin
head:=head*10;
tail:=tail*10+9;
end;
for i:=head to tail do
if check(i) then begin inc(w);s[w]:=i; end;
checks(w);
for i:=1 to w do
if e[i] then inc(sum);
write(sum);
end;
begin
k:=1;
fillchar(e,sizeof(e),true);
readln(a);
for i:=2 to a do
k:=k*i;
if a=1 then write(4)
else if a<5 then trys(a)
else if a=5 then write(0);
end.
a,k,i,w,sum,x:longint;
s:array[1..8363]of longint;
e:array[1..8363]of boolean;
st:string;
b:array[1..5]of char;
flag:array[0..9]of boolean;
c:array[1..120]of string;
procedure search(depth:integer);
var i,t:integer;
begin
if(depth>a) then
begin
inc(x);
for i:=1 to a do c[x]:=c[x]+b[i];
exit;
end;
for i:=1 to a do
if flag[i]=false then
begin
b[depth]:=st[i];
flag[i]:=true;
search(depth+1);
flag[i]:=false;
end;
end;
function erfen(o:string):boolean;
var
m,head,tail,j:longint;
begin
val(o,m);
head:=1;
tail:=w;
j:=trunc((head+tail)/2);
repeat
if s[j]=m then exit(false)
else
if s[j]>m then
begin tail:=j-1; j:=trunc((head+tail)/2) end
else if s[j]
until (head>tail);
exit(true);
end;
procedure checks(w:longint);
var
i,j:longint;
begin
for i:=1 to w do
begin
str(s[i],st);
x:=0;
search(1);
for j:=1 to k do
if erfen(c[j]) then e[i]:=false;
for j:=1 to k do
c[j]:=';
end;
end;
function check(w:longint):boolean;
var
i:longint;
begin
for i:=2 to round(sqrt(w)) do
if w mod i =0 then exit(false);
exit(true);
end;
procedure trys(a:longint);
var
i,j,head,tail:longint;
begin
tail:=9;
head:=1;
w:=0;
for i:=1 to a-1 do
begin
head:=head*10;
tail:=tail*10+9;
end;
for i:=head to tail do
if check(i) then begin inc(w);s[w]:=i; end;
checks(w);
for i:=1 to w do
if e[i] then inc(sum);
write(sum);
end;
begin
k:=1;
fillchar(e,sizeof(e),true);
readln(a);
for i:=2 to a do
k:=k*i;
if a=1 then write(4)
else if a<5 then trys(a)
else if a=5 then write(0);
end.
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1三角形ABC的边BC=48cm,高AD=16cm,矩形EFGH的边FG在BC上,顶点E,H分别在AB,AC上,相邻两边EF,FG比5:9
- 2如图,点I是△ABC的内心,AI的延长线交BC于D,交△ABC的外接圆于E.求证:CE=BE=IE
- 3汽车队把一批钢材从工场运到工地,第一天运了所有钢材的1/4多7吨,第二天运了余下的2/5多2吨,这样还剩下全部钢材的5/18没有运完,问原来有多少吨?算术法的
- 4西周时期,刻在青铜器上的文字称为 金文对吗
- 5I have a book on the desk .的同义词
- 6我们跟着作者来到了 烟台的海 ,不禁想起了什么?
- 7《韩琦大度》翻译
- 8rain是当做动词的时候加s,还是当做名词的时候加s呀
- 9英语翻译
- 10写出一个求满足1×3×5×7×……×n>50000的最小正整数n的算法,并画出相应的程序框图.
热门考点