DIGIT0 - Số 0 tận cùng

Tác giả: ll931110

Ngôn ngữ: Pascal

Program DIGIT0;
        Const
                input  = '';
                output = '';
        Var
                F: array['a'..'z'] of longint;
                s: ansistring;
                n: longint;

Procedure init;
          Var
                fi: text;
                 i: longint;
          Begin
                Assign(fi, input);
                        Reset(fi);

                        Readln(fi, s);
                        n:= length(s);
                        For i:= 1 to n do inc(F[s[i]]);

                Close(fi);
          End;

Function divsum(n,k: longint): longint;
         Var
                  t: longint;
                res: longint;
         Begin
                res:= 0;
                t:= 1;

                While t <= n do
                        Begin
                                t:= t * k;
                                res:= res + n div t;
                        End;

                divsum:= res;
         End;

Procedure solve;
          Var
                   fo: text;
                   ch: char;
                c2,c5: longint;
          Begin
                c2:= divsum(n,2);
                For ch:= 'a' to 'z' do c2:= c2 - divsum(F[ch],2);

                c5:= divsum(n,5);
                For ch:= 'a' to 'z' do c5:= c5 - divsum(F[ch],5);

                Assign(fo, output);
                        Rewrite(fo);
                        If c2 > c5 then writeln(fo, c5) else writeln(fo, c2);
                Close(fo);
          End;

Begin
        init;
        solve;
End.

Download