C11SEQ3 – spoj

Đề bài:

Thuật toán:

  • (đang cập nhập)

Code:

const
        tfi='';//c11seq3.inp';
        tfo='';//c11seq3.out';
 
var
        fi,fo:text;
        n:longint;
        f:array[0..24]of qword;
        t:array[0..5] of qword=(244445,48889, 77789, 155578, 111356, 122227);
 
procedure dao(i:longint);
        var s:string;
                tg:char;
                i1,j,code:longint;
        begin
                str(f[i],s);
                for i1:=1 to length(s)-1 do
                        for j:=i1+1 to length(s) do
                                if s[i1]>s[j] then
                                        begin
                                                tg:=s[i1];
                                                s[i1]:=s[j];
                                                s[j]:=tg;
                                        end;
                val(s,f[i],code);
        end;
 
procedure xuli;
        var i:longint;
        begin
                read(fi,n);
                f[1]:=1;
                for i:=2 to 24 do
                        begin
                                f[i]:=f[i-1]*2;
                                dao(i);
                        end;
                if n<=24 then write(f[n])
                else writeln(fo,t[n mod 6]);
        end;
 
 
begin
        assign(fi,tfi);
        assign(fo,tfo);
        reset(Fi);
        rewrite(fo);
        xuli;
        close(fo);
end.
Khuyên dùng

 

Speak Your Mind

*