高精度模板 存档
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstring>
#define SF scanf
#define PF printf
using namespace std;
typedef long long LL;
const int MAXL = 300;
const int L = 10000;
struct Hp {
int Len, A[MAXL+10];
Hp (int x = 0) {
memset(A, 0, sizeof(A)); Len = 0;
while(x) { A[Len++] = x % L; x /= L; }
}
Hp fix() {
while( Len && !A[Len-1]) Len--;
return *this;
}
Hp operator = (int x) {
memset(A, 0, sizeof(A)); Len = 0;
while(x) { A[Len++] = x % L; x /= L; }
return *this;
}
int operator [] (const int &pos) const { return A[pos]; }
int & operator [] (const int &pos) { return A[pos]; }
Hp operator + (const Hp &b) const {
Hp c;
c.Len = max(Len, b.Len) + 1;
int add = 0;
for(int i = 0; i < c.Len; i++) {
add += A[i] + b[i];
c[i] = add % L;
add /= L;
}
return c.fix();
}
Hp operator - (const Hp &b) const {
Hp c;
c.Len = max(Len, b.Len);
int del = 0;
for(int i = 0; i < c.Len; i++) {
del += A[i] - b[i];
c[i] = del;
del = 0;
if(c[i] < 0) {
int tmp = (-c[i] - 1) / L + 1;
c[i] += tmp * L;
del -= tmp;
}
}
return c.fix();
}
Hp operator * (const Hp &b) const {
Hp c;
c.Len = Len + b.Len;
for(int i = 0; i < Len; i++) {
int mul = 0;
for(int j = 0; j <= b.Len; j++) {
mul += A[i] * b[j] + c[i + j];
c[i + j] = mul % L;
mul /= L;
}
}
return c.fix();
}
Hp operator / (const int &b) const {
Hp c;
c.Len = Len;
int over = 0;
for(int i = Len-1; i >= 0; i--) {
over = over * L + A[i];
c[i] = over / b;
over %= b;
}
return c.fix();
}
Hp operator += (const Hp &b) { *this = *this + b; return *this; }
Hp operator -= (const Hp &b) { *this = *this - b; return *this; }
Hp operator *= (const Hp &b) { *this = *this * b; return *this; }
Hp operator /= (const int &b) { *this = *this / b; return *this; }
bool operator < (const Hp &b) const {
if(Len != b.Len) return Len < b.Len;
for(int i = Len-1; i >= 0; i--)
if(A[i] != b[i]) return A[i] < b[i];
return false;
}
bool operator > (const Hp &b) const { return b < *this; }
bool operator <= (const Hp &b) const { return !(b < *this); }
bool operator >= (const Hp &b) const { return !(*this < b); }
bool operator != (const Hp &b) const { return b < *this || *this < b; }
bool operator == (const Hp &b) const { return !(b < *this) && !(*this < b); }
};
int a[L+10];
void print(const Hp &A)
{
PF("%d", A[A.Len-1]);
for(int i = A.Len-2; i >= 0; i--) PF("%04d", A[i]);
puts("");
}
int main()
{
int T; SF("%d", &T); while(T--) {
int n;
Hp ans = 0, add = 0, del = 0, C = 1;
SF("%d", &n);
for(int i = n; i >= 1; i--) SF("%d", &a[i]);
for(int i = 1; i <= n; i++) {
if(i > 1) C = C * (n - i + 1) / (i - 1);
if(i & 1) add += C * a[i];
else del += C * a[i];
}
if(add < del) {
putchar('-'); ans = del - add;
}
else ans = add - del;
print(ans);
}
}