直接深搜+检验。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF;
int n,tot;
vector<int> vct; int getr(vector<int> &x,int pos)
{
int res=;
for(int i=;i<;++i)
{
res+=x[pos]*x[i]*pow(,i)+0.5;
}
return res;
} bool chk(int x,int dgt)
{
int std=pow(,dgt)+0.5;
if(x>=std)return ;
for(;x;)
{
if(find(vct.begin(),vct.end(),x%)==vct.end())return ;
x/=;
}
return ;
} void dfs(vector<int> &x)
{
if(x.size()==)
{
int res1=getr(x,);
int res2=getr(x,);
int res=res1+res2*; if(chk(res1,)&&chk(res2,)&&chk(res,))
{
//cout<<res1<<" "<<res2<<" "<<res<<endl;
++tot;
}
return;
}
for(int i=;i<vct.size();++i)
{
x.push_back(vct[i]);
dfs(x);
x.pop_back();
}
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
cin>>n;
vct.assign(n,);
for(int i=;i<n;++i)
{
cin>>vct[i];
}
vector<int> tmp;
dfs(tmp);
cout<<tot<<endl;
}
return ;
}