Cho trước số nguyên dương N và M. Hãy tính giá trị của biểu thức N!!! mod M.
Program dothanhydhth_22_03;
Var m,n,i,j: integer;
Function giaithua(n:integer): longint;
begin
if (n=1) or (n=2) then
giaithua:=n
else
giaithua:=giaithua(n-1)*n;
end;
BEGIN
writeln('Chuong trinh nhap N,M va tinh N!!! mod m');
write('Nhap n,m: '); readln(n,m);
writeln('Ket qua can tinh ',giaithua(giaithua(giaithua(n))) mod m);
readln;
END.
[FONT=monospace]#include <conio.h>[/FONT]
[FONT=monospace]#include <iostream.h>[/FONT]
[FONT=monospace]/*Ham tra ve so nguyen tinh n! (Factorial)*/[/FONT]
[FONT=monospace]long int Fac(int n) {[/FONT]
[FONT=monospace] if(n==0)[/FONT]
[FONT=monospace] return 1;[/FONT]
[FONT=monospace] else[/FONT]
[FONT=monospace] return n*Fac(n-1);[/FONT]
[FONT=monospace]}[/FONT]
[FONT=monospace]/*Chuong trinh chinh*/[/FONT]
[FONT=monospace]void main(){[/FONT]
[FONT=monospace] clrscr();[/FONT]
[FONT=monospace] int n;[/FONT]
[FONT=monospace] cout<<"Nhap vao gia tri cua n = ";[/FONT]
[FONT=monospace] cin>>n;[/FONT]
[FONT=monospace] cout<<n<<"! = "<<Fac(n);[/FONT]
[FONT=monospace] getch();[/FONT]
[FONT=monospace]}[/FONT]