Answer the question
In order to leave comments, you need to log in
Rectangle problem (acmp). Why doesn't it pass?
I solved problems on the site acmp.ru, and I came across a seemingly easy problem, but my solution does not pass the test.
The bottom line is that it is required to determine the number of possible rectangles with area from A to B and perimeter from C to D. The full text of the task is acmp.ru/asp/do/index.asp?main=task&id_problem=682.
My solution is to iterate over all possible areas (from A to B) and find two factors whose product equals the current area. Next, we check these sides (multipliers) for compliance with the perimeter.
int count = 0; //счетчик
for(int s = a; s <= b; s++){ //перебираем площади
for(int x = 1; x < s; x++){
if(s%x==0){ //перебираем множители
int y = s/x;
int p = 2*(x+y);
if(p>=c&p<=d&x<=y){ //проверяем периметр и запрещаем повтор(x*y=y*x)
count++;
System.out.println(x+" "+y);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question