# BZOJ3275: Number

## 3275: Number

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 372  Solved: 153
[Submit][Status]

## Description

1:存在正整数C，使a*a+b*b=c*c
2:gcd(a,b)=1

5
3 4 5 6 7

22

## HINT

n<=3000。

s->奇数 连该数的权

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 3000+10
14 #define maxm 10000000
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 #define mod 1000000007
23 using namespace std;
25 {
26     int x=0,f=1;char ch=getchar();
27     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
28     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
29     return x*f;
30 }
32 ll sum,maxflow;
33 struct edge{int go,next,v;}e[maxm];
35 void insert(int x,int y,int z){ins(x,y,z);ins(y,x,0);}
36 bool bfs()
37 {
38     for(int i=s;i<=t;i++)h[i]=-1;
39     int l=0,r=1;q[1]=s;h[s]=0;
40     while(l<r)
41     {
42         int x=q[++l];
44          if(e[i].v&&h[e[i].go]==-1)
45          {
46             h[e[i].go]=h[x]+1;q[++r]=e[i].go;
47          }
48     }
49     return h[t]!=-1;
50 }
51 int dfs(int x,int f)
52 {
53     if(x==t) return f;
54     int tmp,used=0;
55     for(int i=cur[x];i;i=e[i].next)
56      if(e[i].v&&h[e[i].go]==h[x]+1)
57     {
58         tmp=dfs(e[i].go,min(e[i].v,f-used));
59         e[i].v-=tmp;if(e[i].v)cur[x]=i;
60         e[i^1].v+=tmp;used+=tmp;
61         if(used==f)return f;
62     }
63     if(!used) h[x]=-1;
64     return used;
65 }
66 void dinic()
67 {
68     maxflow=0;
69     while(bfs())
70     {
72     }
73 }
74 inline int gcd(int x,int y){return y?gcd(y,x%y):x;}
75 int main()
76 {
77     freopen("input.txt","r",stdin);
78     freopen("output.txt","w",stdout);
80     for1(i,n)
81     {
83         if(x&1)insert(s,i,x);else insert(i,t,x);
84     }
85     for1(i,n)for1(j,n)
86     if((a[i]&1)&&(!(a[j]&1))&&(gcd(a[i],a[j])==1))
87     {
88         ll x=(ll)a[i]*(ll)a[i]+(ll)a[j]*(ll)a[j],y=sqrt(x);
89         if(y*y!=x)continue;
90         insert(i,j,inf);
91     }
92     dinic();
93     cout<<sum-maxflow<<endl;
94     return 0;
95 }
View Code

  ll y=sqrt(x);
return y*y==x;

posted @ 2014-12-13 21:39  ZYF-ZYF  Views(189)  Comments(0Edit  收藏  举报