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 2Example Output
2
Method:
Do someting easy firstly.
\(\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;
}
浮世苍茫,不过瞬逝幻梦
善恶爱诳,皆有定数
于命运之轮中
吞噬于黄泉之冥暗
呜呼,吾乃梦之戍人
幻恋之观者
唯于万华镜中,永世长存

浙公网安备 33010602011771号