You need to write a program that determines the frequency of occurrence in the number x! digits y (x <= 100). I think factorial.
function fact(n : integer) : longint; begin if n <= 1 then fact := 1 else fact := n * fact(n - 1); end;
You need to write a program that determines the frequency of occurrence in the number x! digits y (x <= 100). I think factorial.
function fact(n : integer) : longint; begin if n <= 1 then fact := 1 else fact := n * fact(n - 1); end;
To multiply stupidly used two arrays of numbers. The derivation of the obtained factorial is closed.
program digifact; const ndig=1000; var n, i, dig, highest, j:integer; prod, prod1: array [1..ndig] of integer; begin write('Введите n>'); readln(n); write('Введите цифру>'); readln(dig); for i:=1 to ndig do begin prod[i] := 0; prod1[i] := 0 end; highest:=1; prod[highest] := 1; for i := 2 to n do begin for j:=1 to highest do prod1[j] := prod[j] * i; for j:=1 to highest do begin prod[j] := prod1[j] mod 10; prod1[j+1] := prod1[j+1] + prod1[j] div 10 end; j := highest+1; while prod1[j] > 0 do begin highest := j; prod[j] := prod1[j] mod 10; prod1[j+1] := prod1[j] div 10; inc(j) end end; (* for i:=highest downto 1 do write(prod[i]); writeln; *) j := 0; for i:=1 to highest do if prod[i] = dig then inc(j); writeln('В числе ', n, '! ', j, ' цифр ', dig); end.
13! = 6227020800> 2147483647 = maxlongint
.
To calculate factorial explicitly, you need to use long arithmetic.
PS It seems to me that without explicit calculation of factorial is not enough.
Source: https://ru.stackoverflow.com/questions/81962/
All Articles