首页 > 其他分享 >POJ 3842(质数判断)

POJ 3842(质数判断)

时间:2022-10-25 12:35:12浏览次数:49  
标签:do begin end 质数 len longint 3842 POJ ans


7!=5040

所以这题直接求质数比打一千万的表都快

这提高诉我们阶乘其实不算大&看(算)清数据规模



Program cc;
var
n,t,len,i,j,ans:longint;
s:string;
b:array[0..9] of longint;
procedure dfs(p,l:longint);
var
i:longint;
begin
if l=len then
begin
if p=1 then exit;
for i:=2 to trunc(sqrt(p)) do if (p mod i=0) then exit;
inc(ans);
exit;
end;
for i:=0 to 9 do
if b[i]>0 then
begin
if (i=0) and (l=0) then continue;
dec(b[i]);
dfs(p*10+i,l+1);
inc(b[i]);
end;

end;
begin
readln(t);
while (t>0) do
begin
readln(s);
len:=length(s);
fillchar(b,sizeof(b),0);
for i:=1 to len do inc(b[ord(s[i])-48]);
ans:=0;
for i:=1 to len do
begin
dfs(0,0);
dec(len);
end;
writeln(ans);


dec(t);
end;
end.



标签:do,begin,end,质数,len,longint,3842,POJ,ans
From: https://blog.51cto.com/u_15724837/5794485

相关文章

  • POJ 1125(Floyd)
    裸FloydProgramP1125;constmaxn=100;maxedge=10;NULL=-2139062144;varn,i,j,k,m,v,t,ans:longint;f:array[1..maxn,1..maxn]oflongint;functionmax(a,b:......
  • POJ 1700(过河问题)
    玩过《雷顿》就知道这题可以贪心小等于2人:1,2->3人时:1,3->1<-1,2->1<-否则:1,2->2<-max1,max2->1<-OR:1,max1->1<-2,max2->2<-于是数据规模-2ProgramP1700;vart,n,i,j:long......
  • POJ 3264(STRMQ)
    forj:=1toln(n)/ln(2)  fori:=1ton-(1shlj)+1do    f[i,j]:=min(f[i,j-1],f[i+(1shl(j-1),j-1];f[l,r]:=min(f[l,j],f[r-(1shlj)+1,j];j=ln(r-l+1......
  • POJ 3748(C++的16进制读法 %x)
    P党写几小时的程序C++才几行……首先P的位运算有上限2^30此时即便是int64也会因为补码坑死人的到1shl31时 int64是负数故这个时候不能shr为多出好多位造成以......
  • POJ 2185(最大平铺矩阵)
    DefaultMilkingGridDescription(1<=R<=10,000) *C (1<=C<=75) 的矩阵,求它的最大平铺矩阵,不够的地方可部分平铺,但不可重叠。Input......
  • POJ 3661(贝茜晨练)
    经典Dp,果断记忆化……#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<functional>usingnamespacestd;#defineMAXN10000+10#defineM......
  • POJ 3575(计算几何与二分-无尽的小数处理)
    这题写了将近半个月……总是在D各种Bug总的说来-这题最难应该是在精度处理上11001这组数据过了就说明精度处理差不多了……Programkingdom;constmaxn=100;maxm=10......
  • POJ 3049(输出字母)
    果断搜ProgramP3049;varn,i,j,m:longint;a:array[1..26]ofchar;b:array['a'..'z']ofboolean;c:char;procedureswap(vara,b:char);vart:char;begin......
  • POJ 3289(高精度乘法)
    高精度乘法ProgramP3289;constmaxn=40000;F=10;typearr=recordd:array[1..maxn]oflongint;len,doc:longint;end;varr,m:arr;y:long......
  • POJ 1222(Gauss消元xor版)
    EXTENDEDLIGHTSOUTDescriptionLightsOut就是下图的游戏,给你一个5*6的矩阵. 你的目标是把灯全关上. 0表示关,1表示开.Input第一行为数据......