查看文章 |
Prime Cryptarithm
2009-04-10 20:01
{ ID: lushl932 PROG: crypt1 LANG: PASCAL } program asdf; var n,a,b,c,d,e,aa,bb,t1,t2,t3,ans:longint; s:array[0..10] of longint; f:array[0..10] of boolean; function check(x:longint):boolean; begin check:=true; while x>0 do begin if not f[x mod 10] then begin check:=false; exit; end; x:=x div 10; end; end; begin assign(input,'crypt1.in'); reset(input); assign(output,'crypt1.out'); rewrite(output); readln(n); fillchar(f,sizeof(f),0); for a:=1 to n do begin read(s[a]); f[s[a]]:=true; end; for a:=1 to n do for b:=1 to n do for c:=1 to n do for d:=1 to n do for e:=1 to n do begin if (s[a]=0)or(s[d]=0) then continue; aa:=s[a]*100+s[b]*10+s[c]; bb:=s[d]*10+s[e]; t1:=aa*s[e]; t2:=aa*s[d]; t3:=aa*bb; if (t1>999)or(t2>999)or(t3>9999) then continue; if not ((check(t1))and(check(t2))and(check(t3))) then continue; inc(ans); end; writeln(ans); close(input); close(output); end. |
最近读者: