1 solutions
-
0
C++ :
#include<iostream> #include<algorithm> using namespace std; const int N = 6000; int a[N]; void fact(int n){ fill(a,a+N,0); a[0]=a[1]=1; for (int i=1; i<=n; i++) { for (int j=1; j<=a[0]; j++) a[j]*=i; for (int j=1; j<=a[0]; j++) { a[j+1]+=a[j]/10; a[j]%=10; } while (a[a[0]+1]) { a[0]++; a[a[0]+1]=a[a[0]]/10; a[a[0]]%=10; } } } void output(int a[]){ for (int i=a[0]; i>=1; i--) cout<<a[i]; cout<<endl; } int main(){ int n; cin>>n; fact(n); output(a); return 0; }Pascal :
var i,k,j,n:longint; s:array[1..6000] of integer; f:boolean; begin k:=6000; f:=false; s[k]:=1; readln(n); for j:=1 to n do begin for i:=k downto 1 do s[i]:=s[i]*j; for i:=k downto 1 do if s[i]>=10 then begin s[i-1]:=s[i-1]+s[i] div 10; s[i]:=s[i] mod 10; end; end; for i:=1 to k do if (s[i]>0) or (f) then begin write(s[i]);f:=true;end; end.
- 1
Information
- ID
- 17082
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By