/* ******************************************************************************** */
#include <iostream> //
#include <cstdio> //
#include <cmath> //
#include <cstdlib> //
#include <cstring> //
#include <vector> //
#include <ctime> //
#include <deque> //
#include <queue> //
#include <algorithm> //
#include <map> //
#include <cmath> //
using namespace std; //
//
#define pb push_back //
#define mp make_pair //
#define X first //
#define Y second //
#define all(a) (a).begin(), (a).end() //
#define fillchar(a, x) memset(a, x, sizeof(a)) //
//
void RI(vector< int >&a, int n){a.resize(n); for ( int i=0;i<n;i++) scanf ( "%d" ,&a[i]);} //
void RI(){} void RI( int &X){ scanf ( "%d" ,&X);} template < typename ...R> //
void RI( int &f,R&...r){RI(f);RI(r...);} void RI( int *p, int *q){ int d=p<q?1:-1; //
while (p!=q){ scanf ( "%d" ,p);p+=d;}} void print(){cout<<endl;} template < typename T> //
void print( const T t){cout<<t<<endl;} template < typename F, typename ...R> //
void print( const F f, const R...r){cout<<f<< ", " ;print(r...);} template < typename T> //
void print(T*p, T*q){ int d=p<q?1:-1; while (p!=q){cout<<*p<< ", " ;p+=d;}cout<<endl;} //
//
typedef pair< int , int > pii; //
typedef long long ll; //
typedef unsigned long long ull; //
//
template < typename T> bool umax(T&a, const T&b){ return b<=a? false :(a=b, true );} //
template < typename T> bool umin(T&a, const T&b){ return b>=a? false :(a=b, true );} //
template < typename T> //
void V2A(T a[], const vector<T>&b){ for ( int i=0;i<b.size();i++)a[i]=b[i];} //
template < typename T> //
void A2V(vector<T>&a, const T b[]){ for ( int i=0;i<a.size();i++)a[i]=b[i];} //
//
const double PI = acos (-1); //
//
/* -------------------------------------------------------------------------------- */
namespace FFT {
const static int maxn = 1e5 + 7;
#define L(x) (1 << (x))
double ax[maxn << 2], ay[maxn << 2], bx[maxn << 2], by[maxn << 2]; //需要四倍空间
int revv( int x, int bits) {
int ret = 0;
for ( int i = 0; i < bits; i++) {
ret <<= 1;
ret |= x & 1;
x >>= 1;
}
return ret;
}
void fft( double * a, double * b, int n, bool rev) {
int bits = 0;
while (1 << bits < n) ++bits;
for ( int i = 0; i < n; i++) {
int j = revv(i, bits);
if (i < j)
swap(a[i], a[j]), swap(b[i], b[j]);
}
for ( int len = 2; len <= n; len <<= 1) {
int half = len >> 1;
double wmx = cos (2 * PI / len), wmy = sin (2 * PI / len);
if (rev) wmy = -wmy;
for ( int i = 0; i < n; i += len) {
double wx = 1, wy = 0;
for ( int j = 0; j < half; j++) {
double cx = a[i + j], cy = b[i + j];
double dx = a[i + j + half], dy = b[i + j + half];
double ex = dx * wx - dy * wy, ey = dx * wy + dy * wx;
a[i + j] = cx + ex, b[i + j] = cy + ey;
a[i + j + half] = cx - ex, b[i + j + half] = cy - ey;
double wnx = wx * wmx - wy * wmy, wny = wx * wmy + wy * wmx;
wx = wnx, wy = wny;
}
}
}
if (rev) {
for ( int i = 0; i < n; i++)
a[i] /= n, b[i] /= n;
}
}
int solve(ll a[], int na, ll b[], int nb, ll ans[]) {
int len = max(na, nb), ln;
for (ln = 0; L(ln) < len; ++ln);
len = L(++ln);
for ( int i = 0; i < len ; ++i) {
if (i >= na) ax[i] = 0, ay[i] = 0;
else ax[i] = a[i], ay[i] = 0;
}
fft(ax, ay, len, 0);
for ( int i = 0; i < len; ++i) {
if (i >= nb) bx[i] = 0, by[i] = 0;
else bx[i] = b[i], by[i] = 0;
}
fft(bx, by, len, 0);
for ( int i = 0; i < len; ++i) {
double cx = ax[i] * bx[i] - ay[i] * by[i];
double cy = ax[i] * by[i] + ay[i] * bx[i];
ax[i] = cx, ay[i] = cy;
}
fft(ax, ay, len, 1);
for ( int i = 0; i < len; ++i)
ans[i] = (ll)(ax[i] + 0.5);
return len;
}
#undef L(x)
}
const int maxn = 1e5 + 7;
ll c[maxn << 2], d[maxn << 2], ans[maxn << 2], sum[maxn << 2];
int a[maxn];
int main() {
#ifndef ONLINE_JUDGE
freopen ( "in.txt" , "r" , stdin);
#endif // ONLINE_JUDGE
int T, n;
cin >> T;
while (T --) {
fillchar(c, 0);
fillchar(d, 0);
fillchar(ans, 0);
cin >> n;
int maxv = 0;
for ( int i = 0; i < n; i ++) {
RI(a[i]);
c[a[i]] ++;
umax(maxv, a[i]);
}
maxv ++;
for ( int i = 0; i < maxv; i ++) d[i] = c[i];
int L = FFT::solve(c, maxv, d, maxv, ans);
while (ans[L] <= 0 && L > 1) L --;
L ++;
for ( int i = 0; i < n; i ++) ans[a[i] << 1] --;
for ( int i = 1; i < L; i ++) {
ans[i] >>= 1;
sum[i] = sum[i - 1] + ans[i];
}
ll Result = 0, Total = (ll)n * (n - 1) * (n - 2) / 6;
//sort(a, a + n);
for ( int i = 0; i < n; i ++) {
ll buf = sum[L - 1] - sum[a[i]];
buf -= n - 1;
buf -= (ll)i * (n - i - 1);
buf -= (ll)(n - i - 1) * (n - i - 2) / 2;
Result += buf;
}
printf ( "%.7f\n" , ( double )Result / Total);
}
return 0;
}
/* ******************************************************************************** */
|