百度空间 | 百度首页 
 
查看文章
 
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.

类别:Usaco | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu