1 条题解
-
0
C++ :
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int a[1001]; int ss(int ); int main() { int m,n=0; cin>>m; for(int i=100;i<=m;++i) { int k=0,w,l=i; do { ++k; w=l%10; l/=10; a[k]=w; }while(l!=0); if(ss(i)==0) { if(ss(((i-a[k]*pow(10,k-1))-a[1])/10)==0) { if(ss(i-a[k]*pow(10,k-1))==0&&ss(i-a[k]*pow(10,k-1)-a[k-1]*pow(10,k-2))==0) { if(ss((i-a[1])/10)==0&&ss((i-10*a[2]-a[1])/100)==0) { cout<<i; ++n; } } } } } if(n==0)cout<<"No"; return 0; } int ss(int a) { if(a==1)return 1; else { int x=2; int b=floor(sqrt(a)); while(x<=b&&(a%x!=0)) ++x; if(x>b)return 0; else return 1; } }
Pascal :
var a:array[1..1500]of longint; k,n,i,ff:longint; f:boolean; st:string; procedure pp; var s:array[1..9999]of longint; l,i,j:longint; begin for i:=1 to n do s[i]:=i; k:=n-1;s[1]:=0; for i:=2 to trunc(sqrt(n)) do for j:=2 to n div i do if s[i*j]<>0 then begin s[i*j]:=0; dec(k); end; l:=1; for i:=1 to k do begin while s[l]=0 do inc(l); a[i]:=s[l];inc(l); end; end; function p1(x,y:longint):boolean; var xx,i:longint; flag:boolean; begin flag:=false; for i:=1 to k do if x=a[i] then begin flag:=true; break; end; if flag then if y=1 then exit(true) else begin xx:=1; for i:=1 to y-1 do xx:=xx*10; exit(p1(x mod xx,y-1)); end; exit(false); end; function p2(x,y:longint):boolean; var flag:boolean;i:longint; begin flag:=false; for i:=1 to k do if x=a[i] then begin flag:=true; break; end; if flag then if y=1 then exit(true) else exit(p2(x div 10,y-1)); exit(false); end; function p3(x,y:longint):boolean; var xx,i:longint; begin xx:=1; for i:=1 to y-1 do xx:=xx*10; x:=x mod xx; x:=x div 10; for i:=1 to k do if x=a[i] then begin exit(true); break; end; exit(false); end; begin read(n); pp; ff:=0; for i:=1 to n do begin str(i,st); if p3(i,length(st)) then if p2(i,length(st)) then if p1(i,length(st)) then begin writeln(i); inc(ff); end; end; if ff=0 then writeln('No'); end.
- 1
信息
- ID
- 486
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者