https://www.nowcoder.com/acm/contest/201/C
写了个扩展欧几里得求最小正整数解果断错了
看了下范围 ,可以暴力 x的范围应该在1e6之内
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18;
ll gcd(ll a,ll b)
{
if(b==0)return a;
return gcd(b,a%b);
}
ll a,b,c;
ll p1,p2,q1,q2;
int main()
{
scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&c,&p1,&p2,&q1,&q2);
ll m=a,n=b;
if(n>m)
{
swap(n,m);
}
if(c%(gcd(m,n))!=0)
{
printf("Kuon\n");
return 0;
}
ll ans=inf;
if(a==0&&b==0&&c==0)
{
ll x=-p1/(2.0*p2);
ll y=-q1/(2.0/q2);
for(ll i=-1;i<=1;i++)
{
for(ll j=-1;j<=1;j++)
{
ans=min(ans,p2*(x+i)*(x+i)+p1*(x+i)+q2*(y+j)*(y+j)+q1*(y+j));
}
}
}
else
{
for(ll x=-1000000;x<=1000000;x++)
{
ll y=(c-a*x)/b;
if(a*x+b*y==c)
{
ans=min(ans,p2*x*x+p1*x+q2*y*y+q1*y);
}
}
}
printf("%lld\n",ans);
return 0;
}