Solved

# a smart alogorithm needed

Posted on 1998-12-25

i'm a student and my current project is to write an efficient program that reads 5 complete numbers

a,b,c,d,e,n

for that type of equation:

aX + bY +cZ = d

input - 5 complete numbers

output - the number of solutions to the equation between

n and -n

according to my program i have n^3 possibilities and i'm looking for a more efficient alogorithm.

here is what i did:

#include <iostream.h>

void main ()

{

cout<<"please enter 5 complete numbers"<<'\n';

int a,b,c;

int d;

int n;

int solution = 0;

int na;

int nb;

int nc;

int num_of_solutions = 0;

int counter = 0;

cin>>a>>b>>c>>d>>n;

na = (-1)*n;

nb = (-1)*n;

nc = (-1)*n;

while (nc <= n){

solution = a*na + b*nb + c*nc;

if (solution == d)

num_of_sol ++;

na ++;

if (na == n+1){

nb ++;

na = -n;

}

if (nb == n+1){

nc ++;

nb = -n;

}

counter ++;

}

cout<<num_of_sol<<'\n'<<counter<<'\n';

}

merry christmess to you all.