Pagini recente » Cod sursa (job #695445) | Cod sursa (job #3150901) | Cod sursa (job #868930) | Cod sursa (job #604776) | Cod sursa (job #2787705)
#include <cstdio>
FILE *fin, *fout;
const int DIM = 794;
const int base = 10000;
const int POW = 45;
int n;
typedef int bignum[DIM + 1];
bignum ans;
void multiply(bignum c, bignum a, long long b) {
long long T = 0;
c[0] = a[0];
for(int i = 1; i <= a[0]; i++) {
T += (long long)a[i] * b;
c[i] = T % base;
T /= base;
}
while(T) {
c[++c[0]] = T % base;
T /= base;
}
}
void put(bignum c, long long a, int b) {
for(int i = 1; i <= b; i++) {
multiply(c, c, a);
}
}
void write(bignum a) {
fprintf(fout, "%d", a[a[0]]);
for(int i = a[0] - 1; i > 0; i--) {
if(a[i] < base / 1000) {
fprintf(fout, "000");
} else if(a[i] < base / 100) {
fprintf(fout, "00");
} else if(a[i] < base / 10) {
fprintf(fout, "0");
}
fprintf(fout, "%d", a[i]);
}
}
int main() {
fin = fopen("patrate2.in", "r");
fout = fopen("patrate2.out", "w");
fscanf(fin, "%d", &n);
ans[0] = ans[1] = 1;
put(ans, (1LL << POW), (n * n) / POW);
put(ans, 2, (n * n) % POW);
for(int i = 1; i <= n; i++) {
multiply(ans, ans, i);
}
write(ans);
fclose(fin);
fclose(fout);
return 0;
}