Pagini recente » Cod sursa (job #553146) | Cod sursa (job #2573929) | Cod sursa (job #2397503) | Cod sursa (job #195604) | Cod sursa (job #1394755)
#include <fstream>
#include <vector>
using namespace std;
class nrm {
public:
vector<int> v;
nrm () {
v.push_back (0);
}
nrm (long long x) {
while (x)
v.push_back (x%10),
x /= 10;
}
void operator = (long long x) {
v.clear ();
while (x)
v.push_back (x%10),
x /= 10;
}
void operator *= (nrm b) {
vector<int> c;
for (int i = 0; i < v.size (); i++)
for (int j = 0, t = 0; j < b.v.size () || t; j++, t /= 10) {
if (i + j >= c.size ())
c.push_back (0);
c[i+j] = (t += c[i+j] + v[i] * (j < b.v.size ()?b.v[j]:0) ) % 10;
}
v.clear ();
v = c;
}
friend ostream& operator<< (ostream& fout, const nrm x) {
for (int i = x.v.size ()-1; i >= 0; i--)
fout << x.v[i];
return fout;
}
};
long long lgpow (long long base, int pw) {
if (pw == 1)
return base;
long long x = lgpow (base, pw/2);
x *= x;
if (pw&1)
x *= base;
return x;
}
nrm nrmlgpow (nrm base, int pw) {
if (pw <= 40)
return lgpow (2, pw);
if (pw == 1)
return base;
nrm x = nrmlgpow (base, pw/2);
x *= x;
if (pw&1)
x *= base;
return x;
}
int main()
{
ifstream fin ("patrate2.in");
ofstream fout ("patrate2.out");
int n;
fin >> n;
nrm n2 (1), fact (1), two(2);
for (int i = 1; i <= n; i++) {
nrm x (i);
fact *= x;
}
n2 = nrmlgpow (two, n * n);
//fout << n2 << ' ' << fact << '\n';
fact *= n2;
fout << fact;
return 0;
}