编程求不定方程组 在区间[-100,100]上的整数解的个数,并打印出所有的整...
发布网友
发布时间:2024-10-04 08:56
我来回答
共3个回答
热心网友
时间:2024-10-05 08:33
我先补充一下,我假设x ,y,z 都在[-100,100]。
由上面的式子可以推出:
z = x*y/16
3x + 4y -32 = x * y / 16
算法的空间复杂度,时间杂度度就不分析了。
另外由上面的式子可推出:x * y - 48x - 64y + 512 = 0 ,类似的不定方程的理论和求解方法见:
http://baike.baidu.com/view/375208.htm
http://wenku.baidu.com/view/650d2f80d4d8d15abe234e15.html
java的实现程序如下:
/**
* @author borqs.slieer
*/
public class Test {
final static double MAX_X_VALUE = 100;
final static double MIN_X_VALUE = -100;
final static double MAX_Y_VALUE = 100;
final static double MIN_Y_VALUE = -100;
final static double MAX_Z_VALUE = 100;
final static double MIN_Z_VALUE = -100;
public static void main(String...args){
execute();
}
/**在闭区间[-100,100]中,求解方程组3x+4y-z=32 x*y = 16z*/
public static void execute() {
double x = 0.0;
double y = 0.0;
double z = 0.0;
long count = 0;
for(double i = MIN_X_VALUE; i < MAX_X_VALUE; i++){
for(double j = MIN_Y_VALUE; j < MAX_Y_VALUE; j++){
double ij = i * j;
z = (ij) / 16 ;
if(z < MIN_Z_VALUE || z > MAX_Z_VALUE){
break;
}
if((i * j) % 16 == 0.0){
if(48* i + 64 * j - 512 == ij){
x = i;
y = j;
System.out.println("x,y,z :" + x + "," + y + "," + z);
count ++;
}
}
}
}
System.out.println("count value:" + count);
}
}
执行结果:
x,y,z :-16.0,16.0,-16.0
x,y,z :0.0,8.0,0.0
count value:2
热心网友
时间:2024-10-05 08:35
java代码:
public class EqualizationSolving {
/**
* @author Saler
* @param args
* @target 在区间【-100,100】中求解方程组,3x+4y-z=32 x*y = 16z
*/
public static void main(String[] args) {
Soving();
}
private static void Soving() {
int left = 0;
int right = 0;
int z = 0;
for(int x=-100;x<=100;x++){
for(int y=-100;y<=100;y++){
left = x*y;
right = 16*(3*x+4*y+32);
if(left==right){
z = (x*y)/16;
System.out.println("x="+x+"y="+y+"z="+z);
}
}
}
}
}
c语言实现:
#include<stdio.h>
/**
* @author Saler
* @param args
* @target 在区间【-100,100】中求解方程组,3x+4y-z=32 x*y = 16z
*
*/
int main(void)
{
int left = 0;
int right = 0;
int z=0;
int x,y;
for(x=-100;x<=100;x++){
for(y=-100;y<=100;y++){
left = x*y;
right = 16*(3*x+4*y+32);
if(left==right){
z = (x*y)/16;
printf("x=%d,y=%d,z=%d\n",x,y,z);
}
}
}
return 0;
}
热心网友
时间:2024-10-05 08:32
我是用C编的程序,主要用了三个嵌套的循环,源码如下:
#include "stdio.h"
void main ()
{
int x,y,z;
int num=0;
printf("方程组的解为:\n");
for(x=-100;x<=100;x++)
for(y=-100;y<=100;y++)
for(z=-100;z<=100;z++)
if(!(3*x+4*y-z-32)&&!(x*y-16*z))
{
num++;
printf("x=%3d,y=%3d,z=%3d\n",x,y,z);
}
printf("共有解%d个",num);
getchar();
}