Pagini recente » Cod sursa (job #991943) | Cod sursa (job #1301924) | Cod sursa (job #408844) | Cod sursa (job #2215688) | Cod sursa (job #2785220)
#include <stdio.h>
#include <stdlib.h>
int v[5000];
int powe(int n) {
int p2, nr_cif, p;
p = 27;
p2 = 1 << p;
nr_cif = 1;
while ( n > 0 ) {
if ( n < p ) {
p = n;
p2 = 1 << p;
}
nr_cif = inmultire(nr_cif, p2);
printf("%d ", p2);
n -= p;
}
return nr_cif;
}
int inmultire(int nr_cif, int a) {
int i, t;
t = i = 0;
while ( i < nr_cif || t > 0 ) {
t = t + a * v[i];
v[i] = t % 10;
t /= 10;
i++;
}
if ( i > nr_cif )
return i;
return nr_cif;
}
int fact(int n, int nr_cif) {
int i;
for ( i = 2; i <= n; i++ ) {
nr_cif = inmultire(nr_cif, i);
}
return nr_cif;
}
int main()
{
int n, nr_cif;
FILE *fin, *fout;
fin = fopen("patrate2.in", "r");
fscanf(fin, "%d", &n);
fclose(fin);
v[0] = 1;
nr_cif = powe(n * n);
nr_cif = fact(n, nr_cif);
nr_cif--;
fout = fopen("patrate2.out", "w");
while ( nr_cif >= 0 ) {
fprintf(fout, "%d", v[nr_cif]);
nr_cif--;
}
fprintf(fout, "\n");
fclose(fout);
return 0;
}