public class a {
//一次不定方程 ax+by=c
public static void f1(int a,int b,int c){
for(int x=0;x<=100;x++){//x,y的取值范围为0-100
for(int y=0;y<=100;y++){
if(a*x+b*y==c) {
System.out.println("x="+x+",y="+y);
}
}
}
}
public static void f2(int a,int b,int c){
int x0=0;
int y0=0;
for(int y=0;y<=100;y++){
if((c-(b*y))%a==0){
x0=(c-(b*y))/a;
y0=y;
System.out.println("x="+(c-(b*y))/a+",y="+y);
break;
}
}
for(int i=1;i<10;i++){
System.out.println("x="+(x0+i*b)+",y="+(y0-i*a));
}
}
public static void main(String[] args){
f1(1,1,4);
f2(1,1,4);
}
}
f1适合于求小数量的解数
f2适合于求大数量的解数