Not able to understand the solution of a simple math problem
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I was practicing the following beginner level problem at codechef
Santosh has a farm at Byteland. He has a very big family to look
after. His life takes a sudden turn and he runs into a financial
crisis. After giving all the money he has in his hand, he decides to
sell some parts of his plots. The speciality of his plot is that it is
rectangular in nature. Santosh comes to know that he will get more
money if he sells square shaped plots. So keeping this in mind, he
decides to divide his plot into minimum possible square plots so that
he can get maximum profit out of this.
So your task is to find the minimum number of square plots that can be
formed out of the rectangular plot.
Input
The input consists of T number of test cases. T lines follow. Each
line consists of two integers N and M which denotes the length and
breadth of the rectangle.
Output
Output is a single line which denotes the minimum number of square
plots that can be formed
Constraints
1<=T<=20
1<=M<=10000
1<=N<=10000
Input:
2
10 15
4 6
Output:
6
6
My approach was there could be large number of possible small squares as there are squares of size 1, 2, 3, 4, ..., min(length, breadth).
So I would sum them up.
But when I went through the other people solutions, all of them are doing it as follows:
$$ans = frac(length*breadth)gcd(length*breadth)^2$$
Can anyone explain me how the above equation is an answer to the given problem and how is it derived. The reason why am I asking for help is I just don't want to copy paste or memorize this formula, rather I want to understand the steps how they came to this equation OR it is a standard formula which I am yet unaware of.
Any help is much appreciated.
geometry greatest-common-divisor
add a comment |Â
up vote
0
down vote
favorite
I was practicing the following beginner level problem at codechef
Santosh has a farm at Byteland. He has a very big family to look
after. His life takes a sudden turn and he runs into a financial
crisis. After giving all the money he has in his hand, he decides to
sell some parts of his plots. The speciality of his plot is that it is
rectangular in nature. Santosh comes to know that he will get more
money if he sells square shaped plots. So keeping this in mind, he
decides to divide his plot into minimum possible square plots so that
he can get maximum profit out of this.
So your task is to find the minimum number of square plots that can be
formed out of the rectangular plot.
Input
The input consists of T number of test cases. T lines follow. Each
line consists of two integers N and M which denotes the length and
breadth of the rectangle.
Output
Output is a single line which denotes the minimum number of square
plots that can be formed
Constraints
1<=T<=20
1<=M<=10000
1<=N<=10000
Input:
2
10 15
4 6
Output:
6
6
My approach was there could be large number of possible small squares as there are squares of size 1, 2, 3, 4, ..., min(length, breadth).
So I would sum them up.
But when I went through the other people solutions, all of them are doing it as follows:
$$ans = frac(length*breadth)gcd(length*breadth)^2$$
Can anyone explain me how the above equation is an answer to the given problem and how is it derived. The reason why am I asking for help is I just don't want to copy paste or memorize this formula, rather I want to understand the steps how they came to this equation OR it is a standard formula which I am yet unaware of.
Any help is much appreciated.
geometry greatest-common-divisor
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I was practicing the following beginner level problem at codechef
Santosh has a farm at Byteland. He has a very big family to look
after. His life takes a sudden turn and he runs into a financial
crisis. After giving all the money he has in his hand, he decides to
sell some parts of his plots. The speciality of his plot is that it is
rectangular in nature. Santosh comes to know that he will get more
money if he sells square shaped plots. So keeping this in mind, he
decides to divide his plot into minimum possible square plots so that
he can get maximum profit out of this.
So your task is to find the minimum number of square plots that can be
formed out of the rectangular plot.
Input
The input consists of T number of test cases. T lines follow. Each
line consists of two integers N and M which denotes the length and
breadth of the rectangle.
Output
Output is a single line which denotes the minimum number of square
plots that can be formed
Constraints
1<=T<=20
1<=M<=10000
1<=N<=10000
Input:
2
10 15
4 6
Output:
6
6
My approach was there could be large number of possible small squares as there are squares of size 1, 2, 3, 4, ..., min(length, breadth).
So I would sum them up.
But when I went through the other people solutions, all of them are doing it as follows:
$$ans = frac(length*breadth)gcd(length*breadth)^2$$
Can anyone explain me how the above equation is an answer to the given problem and how is it derived. The reason why am I asking for help is I just don't want to copy paste or memorize this formula, rather I want to understand the steps how they came to this equation OR it is a standard formula which I am yet unaware of.
Any help is much appreciated.
geometry greatest-common-divisor
I was practicing the following beginner level problem at codechef
Santosh has a farm at Byteland. He has a very big family to look
after. His life takes a sudden turn and he runs into a financial
crisis. After giving all the money he has in his hand, he decides to
sell some parts of his plots. The speciality of his plot is that it is
rectangular in nature. Santosh comes to know that he will get more
money if he sells square shaped plots. So keeping this in mind, he
decides to divide his plot into minimum possible square plots so that
he can get maximum profit out of this.
So your task is to find the minimum number of square plots that can be
formed out of the rectangular plot.
Input
The input consists of T number of test cases. T lines follow. Each
line consists of two integers N and M which denotes the length and
breadth of the rectangle.
Output
Output is a single line which denotes the minimum number of square
plots that can be formed
Constraints
1<=T<=20
1<=M<=10000
1<=N<=10000
Input:
2
10 15
4 6
Output:
6
6
My approach was there could be large number of possible small squares as there are squares of size 1, 2, 3, 4, ..., min(length, breadth).
So I would sum them up.
But when I went through the other people solutions, all of them are doing it as follows:
$$ans = frac(length*breadth)gcd(length*breadth)^2$$
Can anyone explain me how the above equation is an answer to the given problem and how is it derived. The reason why am I asking for help is I just don't want to copy paste or memorize this formula, rather I want to understand the steps how they came to this equation OR it is a standard formula which I am yet unaware of.
Any help is much appreciated.
geometry greatest-common-divisor
edited Aug 19 at 16:32
Moo
4,7533920
4,7533920
asked Aug 19 at 6:36
user3243499
180110
180110
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
There is an error that probably you made transcribing the formula used by the other people, it should be
$$rm ans = fraclength times breathgcd(length, breath)^2 $$
Notice that the $gcd$ function in the denominator is doing anything useful only when applying it to $2$ or more operands, not to just one as you did above.
That formula is the solution to a slightly different problem than stated, namely when all the plots of land not only have to be square, but also the same size. Maybe that was the intention of the problem, but it certainly is not stated.
For example, for $rm length = 3, breath = 4$, that formula says the answer is $12$, which amounts to getting $12$ $1times1$ plots. Of course, you can devide this area into 4 squares: one is $3 times 3$, the other 3 are $1 times 1$.
That the given formula is a solution to the altered problem is easy to so, as the common side length of the small square plots needs to divide both the breath and the length of the original farm. The greatest values to do that (which produces the smallest number of plots) is the gcd of both values.
That means you get $rm fraclengthgcd(length, breath)$ small plots in the length direction of the farm and $rm fracbreathgcd(length, breath)$ small plots in the breath direction. Multiply both values and you get the formula above.
The problem you tried to solve (allowing different sizes of plots) may be very hard or very easy (just get the biggest square possible from the remaining farm, the continue recursivly), I'm not sure.
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
add a comment |Â
up vote
0
down vote
The answer makes sense if all square plots must be the same area.
In that case, note that $MN$ is the total area of the rectangle, and $gcd(M,N)$ is the maximum side length of a square which can tesselate the rectangle. Thus, the number of square plots total is $MN/gcd(M,N)^2$, and this is minimized when the square's side length is maximized.
To see why the maximum side length of square plots is $gcd(M,N)$, first assume you tiled the entire plot with squares of side length $x$. Now suppose $x$ is not a common divisor of $M$ and $N$, so either $x nmid M$ or $x nmid N$. WLOG let $x nmid M$; then, we can write $M = qx + r$ for some $0 < r < m$. You cannot tesselate the $M$ by $N$ rectangle with only $x$ by $x$ squares since there would be $r$ units of length remaining in the plot, and that remaining area is too narrow to be tiled by $x$ by $x$ squares. By contradiction, $x$ must be a common divisor of $M$ and $N$. Since choosing the greatest common divisor leads to the fewest square plots, that is the optimal choice.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
There is an error that probably you made transcribing the formula used by the other people, it should be
$$rm ans = fraclength times breathgcd(length, breath)^2 $$
Notice that the $gcd$ function in the denominator is doing anything useful only when applying it to $2$ or more operands, not to just one as you did above.
That formula is the solution to a slightly different problem than stated, namely when all the plots of land not only have to be square, but also the same size. Maybe that was the intention of the problem, but it certainly is not stated.
For example, for $rm length = 3, breath = 4$, that formula says the answer is $12$, which amounts to getting $12$ $1times1$ plots. Of course, you can devide this area into 4 squares: one is $3 times 3$, the other 3 are $1 times 1$.
That the given formula is a solution to the altered problem is easy to so, as the common side length of the small square plots needs to divide both the breath and the length of the original farm. The greatest values to do that (which produces the smallest number of plots) is the gcd of both values.
That means you get $rm fraclengthgcd(length, breath)$ small plots in the length direction of the farm and $rm fracbreathgcd(length, breath)$ small plots in the breath direction. Multiply both values and you get the formula above.
The problem you tried to solve (allowing different sizes of plots) may be very hard or very easy (just get the biggest square possible from the remaining farm, the continue recursivly), I'm not sure.
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
add a comment |Â
up vote
1
down vote
There is an error that probably you made transcribing the formula used by the other people, it should be
$$rm ans = fraclength times breathgcd(length, breath)^2 $$
Notice that the $gcd$ function in the denominator is doing anything useful only when applying it to $2$ or more operands, not to just one as you did above.
That formula is the solution to a slightly different problem than stated, namely when all the plots of land not only have to be square, but also the same size. Maybe that was the intention of the problem, but it certainly is not stated.
For example, for $rm length = 3, breath = 4$, that formula says the answer is $12$, which amounts to getting $12$ $1times1$ plots. Of course, you can devide this area into 4 squares: one is $3 times 3$, the other 3 are $1 times 1$.
That the given formula is a solution to the altered problem is easy to so, as the common side length of the small square plots needs to divide both the breath and the length of the original farm. The greatest values to do that (which produces the smallest number of plots) is the gcd of both values.
That means you get $rm fraclengthgcd(length, breath)$ small plots in the length direction of the farm and $rm fracbreathgcd(length, breath)$ small plots in the breath direction. Multiply both values and you get the formula above.
The problem you tried to solve (allowing different sizes of plots) may be very hard or very easy (just get the biggest square possible from the remaining farm, the continue recursivly), I'm not sure.
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
add a comment |Â
up vote
1
down vote
up vote
1
down vote
There is an error that probably you made transcribing the formula used by the other people, it should be
$$rm ans = fraclength times breathgcd(length, breath)^2 $$
Notice that the $gcd$ function in the denominator is doing anything useful only when applying it to $2$ or more operands, not to just one as you did above.
That formula is the solution to a slightly different problem than stated, namely when all the plots of land not only have to be square, but also the same size. Maybe that was the intention of the problem, but it certainly is not stated.
For example, for $rm length = 3, breath = 4$, that formula says the answer is $12$, which amounts to getting $12$ $1times1$ plots. Of course, you can devide this area into 4 squares: one is $3 times 3$, the other 3 are $1 times 1$.
That the given formula is a solution to the altered problem is easy to so, as the common side length of the small square plots needs to divide both the breath and the length of the original farm. The greatest values to do that (which produces the smallest number of plots) is the gcd of both values.
That means you get $rm fraclengthgcd(length, breath)$ small plots in the length direction of the farm and $rm fracbreathgcd(length, breath)$ small plots in the breath direction. Multiply both values and you get the formula above.
The problem you tried to solve (allowing different sizes of plots) may be very hard or very easy (just get the biggest square possible from the remaining farm, the continue recursivly), I'm not sure.
There is an error that probably you made transcribing the formula used by the other people, it should be
$$rm ans = fraclength times breathgcd(length, breath)^2 $$
Notice that the $gcd$ function in the denominator is doing anything useful only when applying it to $2$ or more operands, not to just one as you did above.
That formula is the solution to a slightly different problem than stated, namely when all the plots of land not only have to be square, but also the same size. Maybe that was the intention of the problem, but it certainly is not stated.
For example, for $rm length = 3, breath = 4$, that formula says the answer is $12$, which amounts to getting $12$ $1times1$ plots. Of course, you can devide this area into 4 squares: one is $3 times 3$, the other 3 are $1 times 1$.
That the given formula is a solution to the altered problem is easy to so, as the common side length of the small square plots needs to divide both the breath and the length of the original farm. The greatest values to do that (which produces the smallest number of plots) is the gcd of both values.
That means you get $rm fraclengthgcd(length, breath)$ small plots in the length direction of the farm and $rm fracbreathgcd(length, breath)$ small plots in the breath direction. Multiply both values and you get the formula above.
The problem you tried to solve (allowing different sizes of plots) may be very hard or very easy (just get the biggest square possible from the remaining farm, the continue recursivly), I'm not sure.
answered Aug 19 at 7:08
Ingix
2,225125
2,225125
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
add a comment |Â
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
You seemed to have posted your answer twice.
â Jazzachi
Aug 19 at 7:10
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
Yes, that was due to an edit which incorrectly came out as a new post. I deleted the one version that the above one superseded. Basically it's the last paragraph, where I'm not sure about the difficulty of the problem the OP tried to solve.
â Ingix
Aug 19 at 7:24
add a comment |Â
up vote
0
down vote
The answer makes sense if all square plots must be the same area.
In that case, note that $MN$ is the total area of the rectangle, and $gcd(M,N)$ is the maximum side length of a square which can tesselate the rectangle. Thus, the number of square plots total is $MN/gcd(M,N)^2$, and this is minimized when the square's side length is maximized.
To see why the maximum side length of square plots is $gcd(M,N)$, first assume you tiled the entire plot with squares of side length $x$. Now suppose $x$ is not a common divisor of $M$ and $N$, so either $x nmid M$ or $x nmid N$. WLOG let $x nmid M$; then, we can write $M = qx + r$ for some $0 < r < m$. You cannot tesselate the $M$ by $N$ rectangle with only $x$ by $x$ squares since there would be $r$ units of length remaining in the plot, and that remaining area is too narrow to be tiled by $x$ by $x$ squares. By contradiction, $x$ must be a common divisor of $M$ and $N$. Since choosing the greatest common divisor leads to the fewest square plots, that is the optimal choice.
add a comment |Â
up vote
0
down vote
The answer makes sense if all square plots must be the same area.
In that case, note that $MN$ is the total area of the rectangle, and $gcd(M,N)$ is the maximum side length of a square which can tesselate the rectangle. Thus, the number of square plots total is $MN/gcd(M,N)^2$, and this is minimized when the square's side length is maximized.
To see why the maximum side length of square plots is $gcd(M,N)$, first assume you tiled the entire plot with squares of side length $x$. Now suppose $x$ is not a common divisor of $M$ and $N$, so either $x nmid M$ or $x nmid N$. WLOG let $x nmid M$; then, we can write $M = qx + r$ for some $0 < r < m$. You cannot tesselate the $M$ by $N$ rectangle with only $x$ by $x$ squares since there would be $r$ units of length remaining in the plot, and that remaining area is too narrow to be tiled by $x$ by $x$ squares. By contradiction, $x$ must be a common divisor of $M$ and $N$. Since choosing the greatest common divisor leads to the fewest square plots, that is the optimal choice.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The answer makes sense if all square plots must be the same area.
In that case, note that $MN$ is the total area of the rectangle, and $gcd(M,N)$ is the maximum side length of a square which can tesselate the rectangle. Thus, the number of square plots total is $MN/gcd(M,N)^2$, and this is minimized when the square's side length is maximized.
To see why the maximum side length of square plots is $gcd(M,N)$, first assume you tiled the entire plot with squares of side length $x$. Now suppose $x$ is not a common divisor of $M$ and $N$, so either $x nmid M$ or $x nmid N$. WLOG let $x nmid M$; then, we can write $M = qx + r$ for some $0 < r < m$. You cannot tesselate the $M$ by $N$ rectangle with only $x$ by $x$ squares since there would be $r$ units of length remaining in the plot, and that remaining area is too narrow to be tiled by $x$ by $x$ squares. By contradiction, $x$ must be a common divisor of $M$ and $N$. Since choosing the greatest common divisor leads to the fewest square plots, that is the optimal choice.
The answer makes sense if all square plots must be the same area.
In that case, note that $MN$ is the total area of the rectangle, and $gcd(M,N)$ is the maximum side length of a square which can tesselate the rectangle. Thus, the number of square plots total is $MN/gcd(M,N)^2$, and this is minimized when the square's side length is maximized.
To see why the maximum side length of square plots is $gcd(M,N)$, first assume you tiled the entire plot with squares of side length $x$. Now suppose $x$ is not a common divisor of $M$ and $N$, so either $x nmid M$ or $x nmid N$. WLOG let $x nmid M$; then, we can write $M = qx + r$ for some $0 < r < m$. You cannot tesselate the $M$ by $N$ rectangle with only $x$ by $x$ squares since there would be $r$ units of length remaining in the plot, and that remaining area is too narrow to be tiled by $x$ by $x$ squares. By contradiction, $x$ must be a common divisor of $M$ and $N$. Since choosing the greatest common divisor leads to the fewest square plots, that is the optimal choice.
answered Aug 19 at 7:11
theyaoster
1,210313
1,210313
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2887420%2fnot-able-to-understand-the-solution-of-a-simple-math-problem%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password