Savior

Savior

Misha decided to help Pasha and Akim be friends again. He had a cunning plan — to destroy all the laughy mushrooms. He knows that the laughy mushrooms can easily burst when they laugh. Mushrooms grow on the lawns. There are a[t] mushrooms on the t-th lawn.
Misha knows that the lawns where the mushrooms grow have a unique ability. A lawn (say, i) can transfer laugh to other lawn (say, j) if there exists an integer (say, b) such, that some permutation of numbers a[i],a[j] and b is a beautiful triple ( i≠j). A beautiful triple is such three pairwise coprime numbers x,y,z, which satisfy the following condition: \(x^2+y^2=z^2\).
Misha wants to know on which minimal number of lawns he should laugh for all the laughy mushrooms to burst.

Input

The first line contains one integer\(n (1≤n≤10^6)\)which is the number of lawns. The next line contains n integers a i which are the number of mushrooms on the i-lawn\((1≤a_i≤10^7).\)All the numbers are different.

Output

Print a single number — the minimal number of lawns on which Misha should laugh for all the mushrooms to burst.

Example Input

2

1 2

Example Output

2

Method:

Do someting easy firstly.

\[x^2+y^2=z^2\\ \therefore 2\mid xyz \ \\\ \because (x,y)=(x,z)=(y,z)=1\\ if\ 2\mid z\\ \because 2\mid z\\ \therefore 2\not\mid xy\\ \because x,y \equiv 1 (mod\ 2)\\ \therefore x^2,y^2 \equiv 1 (mod\ 4)\\ \because x^2+y^2 \equiv 2 \not \equiv 0 \equiv z^2(mod\ 4)\\ \therefore 2 \not \mid z\ \And 2 \mid xy\\ Let\ 2t\ be\ the\ equal\ of\ y(t\in N^+)\\ \therefore 2\not \mid x\\ x^2=z^2-y^2=(z-y)(z+y)\\ \forall \ w\mid z-y(w>2\And w\in N^+\And 2 \not \mid w)\\ \because Let\ (wu+r)\ be\ the\ equal\ of\ z(u,r\in N^+)\\ \therefore Let\ (wv+r)\ be\ the\ equal\ of\ y(v\in N^+)\\ \because z+y=w(u+v)+2r\\ \therefore z+y \equiv 2r(mod\ w)\\ \because (2,w)=1,w\not \mid r\\ \therefore w\not \mid z+y\\ \because x^2=(z-y)(z+y)\\ \therefore w^2 \mid z-y\\ \therefore z-y=o^2(o\in N^+)\\ \because z+y=\frac{x^2}{z-y}=(\frac{x}{o})^2\\ \therefore \left\{ \begin{array}{c} z-y=o^2\\ z+y=(\frac{x}{o})^2 \end{array}\right.\\ \left\{ \begin{array}{c} z=\frac{o^2+(\frac{x}{o})^2}{2}\\ y=\frac{(\frac{x}{o})^2-o^2}{2} \end{array}\right.\\ enumerate\ o\And \frac{x}{o}\\ Time\ complexity\ is\ O(m) \]

\(\mathfrak{Talk\ is\ cheap,show\ you\ the\ code.}\)

#include<set>
#include<cmath>
#include<vector>
#include<cstdio>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
# define read read1<int>()
# define Type template<typename T>
Type inline const T read1()
{
    T m=0;
    char k=getchar();
    while(('0'>k||k>'9')&&(k!='-'))k=getchar();
    const bool f=(k=='-'?1:0);
    if(f)k=getchar();
    while('0'<=k&&k<='9')m=(m<<3)+(m<<1)+(k^48),k=getchar();
    return f?-m:m;
}
# define ll long long
int a[1000005],s,w[50000005],ans;
int Find(int n,int* x=a){if(x[n]^n)x[n]=Find(x[n]);return x[n];}
void Merge(int u,int v,int* x=a){
	if(Find(u,x)!=Find(v,x)){
		x[x[u]]=x[v];
		--ans;
	}
}
int main(){
	s=read;
	for(int i=1;i<=s;++i)a[i]=i,w[read]=i;
	ans=s;
	for(int x=1;x*x<24999999;x+=2)
		for(int y=x+2;y*y<25000000;y+=2)
			if(__gcd(x,y)==1){
				int c=y*y+x*x>>1,b=y*y-x*x>>1,a=x*y;
				if(w[a]){
					if(w[b])Merge(w[a],w[b]);
					if(w[c])Merge(w[a],w[c]);
				}
				else
					if(w[b]&&w[c])
						Merge(w[b],w[c]);
			}
	printf("%d",ans);
	return 0;
}
posted @ 2020-07-16 15:32  ファイナル  阅读(222)  评论(0)    收藏  举报