题意:中文题。
分析:水容斥,因为才10^9所以最多能选9个数。直接dfs所以情况,加个剪枝mul>10^9即可。
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=10000010;
const int MAX=151;
const int mod=100000000;
const int MOD1=100000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000000;
const ll INF=10000000010;
typedef double db;
typedef unsigned long long ull;
int k,a[60];
ll ans;
ll gcd(ll x,ll y) {
return y ? gcd(y,x%y):x;
}
ll lcm(ll x,ll y) {
return x/gcd(x,y)*y;
}
void dfs(int x,int g,ll mul) {
if (mul>MOD) return ;
if (x==k+1) {
if (g&1) ans-=MOD/mul;
else ans+=MOD/mul;
return ;
}
dfs(x+1,g,mul);
dfs(x+1,g+1,lcm(mul,a[x]));
}
int main()
{
int i,j,n,t,bo;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i=1;i<=n;i++) scanf("%d", &a[i]);
sort(a+1,a+n+1);
ans=0;k=0;
for (i=1;i<=n;i++) {
bo=0;
for (j=k;j;j--)
if (a[i]%a[j]==0) { bo=1;break ; }
if (!bo) a[++k]=a[i];
}
dfs(1,0,1ll);
printf("%lld\n", ans);
}
return 0;
}