CWAY - Đếm số đường đi trên đồ thị đầy đủ
Tác giả: ladpro98
Ngôn ngữ: C++
#include <bits/stdc++.h>
const int MOD = 100000;
using namespace std;
typedef vector<int> BigInt;
int n;
BigInt operator + (BigInt a, BigInt b) {
BigInt c; int carry = 0;
for(int i = 0; i < a.size() || i < b.size(); i++) {
if (i < a.size()) carry += a[i];
if (i < b.size()) carry += b[i];
c.push_back(carry % MOD);
carry /= MOD;
}
if (carry) c.push_back(carry);
return c;
}
BigInt operator * (BigInt a, int b) {
BigInt c; int carry = 0;
for(int i = 0; i < a.size(); i++) {
carry += a[i] * b;
c.push_back(carry % MOD);
carry /= MOD;
}
if (carry) c.push_back(carry);
return c;
}
void print(BigInt a) {
printf("%d", a[a.size() - 1]);
for(int i = a.size() - 2; i >= 0; i--)
printf("%05d", a[i]);
printf("\n");
}
int main() {
scanf("%d", &n);
BigInt res; res.push_back(1);
BigInt tmp = res;
for(int i = n - 2; i; i--) {
tmp = tmp * i;
res = res + tmp;
}
print(res);
return 0;
}