对每个数分解质因数,然后对每个质因子有一个异或方程,
解异或方程,记其中自由元的个数为f,答案即为 2f−1。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
const int MAXN = 105, Nya = -1;
typedef int Array[MAXN][MAXN];
typedef int Seq[MAXN];
typedef int Array2[MAXN<<1][MAXN];
int t, m, ans;
Seq prime;int tot;
Seq b; Array a;
Array2 u; Seq x;
void GetPrime()
{
for(int i = 2; tot < t; i++)
{
bool tag = true;
for(int j = 1; j <= tot && tag; j++)
if(!(i % prime[j])) tag = false;
if(tag) prime[++tot] = i;
}
}
void PrimeFactor(int px,int r[])
{
for(int i = 1; i <= t && i <= px; i++)
while(!(px % prime[i]))
px /= prime[i], r[i] ^= 1;
}//r[i] x->prime[i]
// XorSum(P[i]*a[i][j]) = 0
int Guass()
{
int ret = 0;
for(int i = 1; i <= m; i++)
{
int g = Nya;
for(int q = i; q <= t; q++)
if(u[q][i]) g = q;
if(g != i)
{
if(g == Nya) g = ++t, ret++;
for(int j = 1; j <= m; j++)
std::swap(u[i][j],u[g][j]);
}
for(int q = i+1; q <= t; q++)
{
if(!u[q][i]) continue;
for(int j = i; j <= m; j++)
u[q][j] ^= u[i][j];
}
}
for(int i = m; i >= 1; i--)
for(int j = i + 1; j <= m; j++)
x[i] ^= x[j] * u[i][j];
for(int i = 1; i <= t; i++)
{
int calcu = 0;
for(int j = 1; j <= m; j++)
calcu ^= x[j] * u[i][j];
if(calcu) return -1;
}
return ret;
}
struct BigNum
{
int num[MAXN],l;
void prt()
{
if(!l) {printf("0");return;}
for(int i = l; i >= 1; i--)
printf("%d",num[i]);
}
}emp;
BigNum operator +(const BigNum &a,const BigNum &b)
{
BigNum ret = emp;
ret.l = std::max(a.l,b.l);
for(int i = 1; i <= ret.l; i++)
ret.num[i] = a.num[i] + b.num[i];
for(int i = 1; i <= ret.l; i++)
if(ret.num[i] >= 10)
ret.num[i] -= 10, ret.num[i+1] ++;
if(ret.num[ret.l + 1]) ret.l++;
return ret;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("sgu200.in","r",stdin);
freopen("sgu200.out","w",stdout);
#endif
std::cin >> t >> m;
GetPrime();
for(int i = 1; i <= m; i++)
{
std::cin >> b[i];
PrimeFactor(b[i],a[i]);
}
for(int i = 1; i <= t; i ++)
for(int j = 1; j <= m; j++)
u[i][j] = a[j][i];
ans = Guass();
if(ans == Nya) puts("0");
else
{
BigNum s = emp, h = emp;
h.num[1] = 1, h.l = 1;
for(int i = 1; i <= ans; i++)
s = s + h, h = h + h;
s.prt(); puts("");
}
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。