-
Notifications
You must be signed in to change notification settings - Fork 0
/
623.cpp
85 lines (69 loc) · 1.08 KB
/
623.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<stdio.h>
/* 500! - 623 */
int t1,t2,n1[3000],vet[1001][3000];
int converte(int num){
int i,aux1,aux2,ant;
t1=0;
aux1=10;
aux2=1;
ant=0;
while(num/aux2>0)
{
n1[t1]=(num%aux1-ant)/aux2;
ant=num%aux1;
aux1*=10;
aux2*=10;
t1++;
}
return 0;
}
int multiplica (int t1,int t2,int num){
int i,j,k,aux=0;
for(i=0;i<t2;i++)
{
k=aux;
for(j=0;j<t1;j++)
{
vet[num][k]+=vet[num-1][i]*n1[j];
k++;
}
aux++;
}
for(i=0;i<=k;i++)
if(vet[num][i]>9)
{
vet[num][i+1]+=vet[num][i]/10;
vet[num][i]=vet[num][i]%10;
}
return i;
}
main(){
int i,j,num,aux[1001];
n1[0]=1;
t1=1;
t2=1;
for(i=1;i<1001;i++)
for(j=0;j<3000;j++)
vet[i][j]=0;
for(i=0;i<1001;i++)
aux[i]=0;
vet[0][0]=vet[1][0]=1;
for(i=2;i<=1000;i++)
{
converte(i);
t2=multiplica(t1,t2,i);
}
for(i=0;i<=1000;i++)
for(j=t2;j>=0;j--)
if(vet[i][j]==0)
aux[i]++;
else
break;
while(scanf("%d",&num)!=EOF)
{
printf("%d!\n",num);
for(i=t2-aux[num];i>=0;i--)
printf("%d",vet[num][i]);
printf("\n");
}
}