常用技巧,答案除以2
#include <bits/stdc++.h>
using namespace std;
typedef int LL;
const LL maxn = 10000;
const LL maxm = 4000000;
const LL inf = 0x3f3f3f3f;
struct mcmf{
LL he[maxn],tot,edge[maxm],ne[maxm],ver[maxm],cost[maxm];
LL pre[maxn],d[maxn];
bool vis[maxn];
LL n;
void init(LL x){
n = x;
tot = 1;
for( LL i = 0;i <= n;i++ ) he[i] = 0;
}
void add(LL x,LL y,LL cap,LL c){
ver[++tot] = y;
ne[tot] = he[x];
he[x] = tot;
edge[tot] = cap;
cost[tot] = c;
ver[++tot] = x;
ne[tot] = he[y];
he[y] = tot;
edge[tot] = 0;
cost[tot] = -c;
}
bool spfa(LL s,LL t){
queue<LL>q;
for(LL i = 0;i <= n;i++){
d[i] = inf;
vis[i] = false;
pre[i] = -1;
}
d[s] = 0;
vis[s] = true;
q.push(s);
while(!q.empty()){
LL x = q.front();
q.pop();
vis[x] = false;
for(LL cure = he[x]; cure ;cure = ne[cure]){
LL y = ver[cure];
if(edge[cure] && d[y] > d[x] + cost[cure] ){
d[y] = d[x] + cost[cure];
pre[y] = cure;
if(!vis[y]){
vis[y] = true;
q.push(y);
}
}
}
}
if(pre[t] == -1)return false;
else return true;
}
LL mincost(LL s,LL t,LL &cc){
LL flow = 0;
cc = 0;
while(spfa(s,t)){
LL mn = inf;
for(LL cure = pre[t];cure != -1;cure = pre[ ver[cure^1] ]){
if(mn > edge[cure])
mn = edge[cure];
}
for(LL cure = pre[t];cure != -1;cure = pre[ ver[cure^1] ]){
edge[cure] -= mn;
edge[cure^1] += mn;
cc += cost[cure] * mn;
}
flow += mn;
}
return flow;
}
} g;
LL s[1000005];
LL gcd( LL x,LL y ){
if( y > x ) swap( x,y );
if( !y ) return x;
return gcd( y,x%y );
}
bool solve( LL x,LL y ){
LL xx = x*x;
LL yy = y*y;
if( !s[ xx -yy ] ) return false;
LL z = s[ xx - yy ];
if( gcd( y,z ) != 1LL ) return false;
return true;
}
int main()
{
memset( s,0,sizeof( s ) );
for( LL i = 1;i * i <= 1000000;i++ ){
s[i*i] = i;
}
LL a,b;
scanf("%d%d",&a,&b);
LL SS = 0,TT = 2*b+1;
g.init( TT );
for( LL i = a;i <= b;i++ ){
for( LL j = i+1;j <= b;j++ ){
if( solve( j,i ) ){
g.add( i,j+b,1,-(i+j) );
g.add( j,i+b,1,-(i+j) );
}
}
}
for( LL i = a;i <= b;i++ ){
g.add( SS,i,1,0 );
g.add( i+b,TT,1,0 );
}
LL cost;
LL maxflow = g.mincost( SS,TT,cost );
cost /= 2;
cost = -cost;
maxflow /= 2;
printf("%d %d",maxflow,cost);
return 0;
}