https://www.codechef.com/problems/RECTSQ
My Code:
#include <stdio.h>
int ans;
int finder (int a, int b)
{
if(b > a)
{
a += b;
b = a-b;
a = a-b;
}
int k = a/b;
ans += k;
if(a-(k*b))
finder((a-(k*b)),b);
else
return 0;
}
int main()
{
int t;
scanf(" %d",&t);
while(t--)
{
int a, b;
scanf(" %d%d",&a,&b);
ans = 0;
finder(a,b);
printf("%d\n",ans);
}
}
I know it is giving output as 3 even for the sample testcases given in the question, while the desired ones are 6 and 6. But I want to ask that if we have to return the minimum number of square plots then why is this incorrect? Take the first case 10, 15 for example, Square 1: 10x10 (5x10 remains from original 10x15) Square 2: 5x5 (5x5 remains from original 5x10) Square 3: 5x5 (Return to main)
So Minimum is 3 squares, why is 6 the answer? I think maybe I understood the question wrong, please help.
Thank You