不难想到,先枚举建图然后跑最大费用最大流
也不难想到一种将每个数拆成两个点i1,i2,所有满足条件的数之间
把所有满足条件之间的数x,y连边x1--->y2,y1--->x2,流量为1,费用为(x+y)
相当于流量费用都变成了原来的2倍
最后再除一下即可
1 const inf=10000007; 2 type node=record 3 point,flow,cost,next:longint; 4 end; 5 6 var edge:array[0..200010] of node; 7 v:array[0..5010] of boolean; 8 q:array[0..500010] of longint; 9 pre,d,cur,p:array[0..5010] of longint; 10 k,ans,len,a,b,i,j,t:longint; 11 12 function min(a,b:longint):longint; 13 begin 14 if a>b then exit(b) else exit(a); 15 end; 16 17 procedure add(x,y,f,c:longint); 18 begin 19 inc(len); 20 edge[len].flow:=f; 21 edge[len].point:=y; 22 edge[len].cost:=c; 23 edge[len].next:=p[x]; 24 p[x]:=len; 25 end; 26 27 function gcd(x,y:longint):longint; 28 begin 29 if y=0 then exit(x) 30 else exit(gcd(y,x mod y)); 31 end; 32 33 function spfa:boolean; 34 var i,j,x,y,f,r:longint; 35 begin 36 for i:=0 to t do 37 d[i]:=-inf; 38 fillchar(v,sizeof(v),false); 39 d[0]:=0; 40 f:=1; 41 r:=1; 42 q[0]:=0; 43 while f<=r do 44 begin 45 x:=q[f]; 46 v[x]:=false; 47 i:=p[x]; 48 while i<>-1 do 49 begin 50 y:=edge[i].point; 51 if edge[i].flow>0 then 52 if d[y]<d[x]+edge[i].cost then 53 begin 54 d[y]:=d[x]+edge[i].cost; 55 pre[y]:=x; 56 cur[y]:=i; 57 if not v[y] then 58 begin 59 v[y]:=true; 60 inc(r); 61 q[r]:=y; 62 end; 63 end; 64 i:=edge[i].next; 65 end; 66 inc(f); 67 end; 68 if d[t]=-inf then exit(false) else exit(true); 69 end; 70 71 function maxcost:longint; 72 var i,j:longint; 73 begin 74 maxcost:=0; 75 while spfa do 76 begin 77 i:=t; 78 while i<>0 do 79 begin 80 j:=cur[i]; 81 dec(edge[j].flow); 82 inc(edge[j xor 1].flow); 83 i:=pre[i]; 84 end; 85 ans:=ans+1; 86 inc(maxcost,d[t]); 87 end; 88 end; 89 90 begin 91 len:=-1; 92 fillchar(p,sizeof(p),255); 93 readln(a,b); 94 t:=b*2+1; 95 for i:=a to b do 96 begin 97 for j:=a to i-1 do 98 begin 99 k:=sqr(i)-sqr(j); 100 if (sqrt(k)=trunc(sqrt(k))) and (gcd(trunc(sqrt(k)),j)=1) then 101 begin 102 add(i,j+b,1,i+j); 103 add(j+b,i,0,-i-j); 104 add(j,i+b,1,i+j); 105 add(i+b,j,0,-i-j); 106 end; 107 end; 108 add(0,i,1,0); 109 add(i,0,0,0); 110 add(i+b,t,1,0); 111 add(t,i+b,0,0); 112 end; 113 k:=maxcost; 114 writeln(ans div 2,' ',k div 2); 115 end.