The equation to which you want to find the roots is:
x * y = 1700/57
You need, for your solution space, two real numbers x
and y
. But x
and y
are not any real numbers, they are positive reals and can be represented by the fraction of two integers a/b
, whereas 1 <= a,b <= 300
. Note also that x = a_x/b_x
and that y = a_y/b_y
, there is no equality or difference between a_x, b_x, a_y, b_y
, the four integer variables being independent of each other.
It means that:
As we are assured that a_x, b_x, a_y, b_y
are integer between 1 and 300 (closed), this means two things:
- a_x * a_y = 1700
- b_x * b_y = 57
What is basically restricted to find two splitters of 1700 both between 1 and 300, and two splitters of 57 between 1 and 300.
Splitters of 57
To find all pairs of 57 divisors between 1 and 300, we need to check which are the numbers in this range that divide 57 and then check if their counterpoint is less than 300.
I won’t demonstrate, but just go through the whole numbers in the interval [1, 57]
for the variable b_x
, then b_y = 57/b_x
. No additional need to check b_y
.
Code to find all factors b_x
:
int bx_candidato;
for (bx_candidato = 1; bx_candidato <= 57; bx_candidato++) {
if (57 % bx_candidato == 0) {
printf("b_x %d, b_y %d\n", bx_candidato, 57/bx_candidato);
}
}
Storing the results in a vector is for a later time
Splitters of 1700
The idea is the same as the 57 divisors, but here it is necessary to verify whether a_y <= 300
. It is also necessary to search only in the interval [1,300]
, because it has no mathematical device to reduce the search scope.
Therefore:
int ax_candidato;
for (ax_candidato = 1; ax_candidato <= 300; ax_candidato++) {
if (1700 % ax_candidato == 0 && 1700/ax_candidato <= 300) {
printf("a_x %d, a_y %d\n", ax_candidato, 1700/ax_candidato);
}
}
Storing the results in a vector is for a later time
Resolving the issue
Note that find a_x
implies the existence of only one a_y
, as well as b_x
and b_y
.
The heart of your problem you can find here:
int divisores_1700[300];
int divisores_encontrados_1700 = 0;
int divisores_57[57];
int divisores_encontrados_57 = 0;
int ax_candidato;
int bx_candidato;
for (bx_candidato = 1; bx_candidato <= 57; bx_candidato++) {
if (57 % bx_candidato == 0) {
divisores_57[divisores_encontrados_57] = bx_candidato;
divisores_encontrados_57++;
}
}
for (ax_candidato = 1; ax_candidato <= 300; ax_candidato++) {
if (1700 % ax_candidato == 0 && 1700/ax_candidato <= 300) {
divisores_1700[divisores_encontrados_1700] = ax_candidato;
divisores_encontrados_1700++;
}
}
On top of the values found, any combination of divisores_57
with divisores_1700
meets the problem. To find all these combinations:
int i, j;
for (i = 0; i < divisores_encontrados_57; i++) {
for (j = 0; j < divisores_encontrados_1700; j++) {
int a_x, a_y, b_x, b_y;
a_x = divisores_1700[j];
a_y = 1700/a_x;
b_x = divisores_57[i];
b_y = 57/b_x;
printf("(%d/%d) * (%d/%d) == 1700/57\n", a_x, b_x, a_y, b_y);
}
}
See working on ideone.
Unaccompanied by text, it is difficult to distinguish its need
– Jefferson Quesado
I am in need of a program whose , me gives the possibilities of the following equation: x*y =1700/57. where x and y are positive reals resulting from two different integer numbers from 0 to 300.
– Pedro Joao
I’m new to this site, I don’t know how you put it right
– Pedro Joao
Edit your question, make it clear to those who are coming to it, reading it the first time
– Jefferson Quesado
Welcome to Stackoverflow! Please explain the problem better, and if possible include a example of code that reproduces what is happening, because your question is not noticeable. See Help Center How to Ask.
– Jefferson Quesado
@Pedrojoao, below the body of the question, has the tags [
c
,c++
..] below has [compartilhar
,editar
, ... ] or edit– NoobSaibot
Welcome to Stackoverflow in Portuguese, you might want to make a Tour: http://answall.com/tour or take a look at Help Center: http://answall.com/tour. and check how to ask questions in a way that is quickly answered, try to inform what you have tried and post your code, hardly anyone will do the job for you. Since you do not have an idea of how to do what you need, initially it is better to do a survey and then if you have some difficulty in programming you can ask again here.
– Jefferson Quesado
What error is displayed? The program does not print the expected result?
– Jefferson Quesado
I’ve seen...obg. I’m editing here
– Pedro Joao
the program does not print the saved values
– Pedro Joao
Vector values are not being changed. It must be printing either zero or random memory junk
– Jefferson Quesado
Note also that iterating over 300 elements is in the range closed at 0 and opened at 300; or
i = 0; i < 300; i++
– Jefferson Quesado
Note also that
a%b == 0
is you verify thata
is multiple ofb
, this operation alone will not return true to all cases ofa
andb
true. How1700
is not multiple of57
, there are no two integers such thata*b == 1700/57
. Have some mistake in the statement or in assuming that there is solution space with two integers– Jefferson Quesado
What I need is a program that gives me the possibilities and is filtered by the conditions imposed by the program: For example : x*y=1700/57; where both x and y are numbers resulting from the division of two numbers("a" and "b") both integers and not necessarily multiples of each other in the range of [1:300]
– Pedro Joao
You say that
x
andy
are real positive resulting ofa
andb
. Is this result obtained by a division? Subtraction?– Jefferson Quesado
Ah, great editing. Now I understand your problem.
– Jefferson Quesado
give up this challenge. too hard...
– Pedro Joao
Has the answer answered your questions? Then it is the case of mark the answer as accepted. If you have an answer that really helped you, mark it as accepted. If you arrived at the solution yourself, post the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.
– Jefferson Quesado
thanks for the help]
– Pedro Joao