updated at 2022. 12. 20. 오후 11:33:55

This commit is contained in:
rl544
2022-12-20 23:33:54 +09:00
parent 4f762a6e7f
commit 4d2246dee2
+3 -12
View File
@@ -2,17 +2,8 @@
class Solution { class Solution {
public int[] solution(int brown, int yellow) { public int[] solution(int brown, int yellow) {
int[] answer = {}; int a = (brown + 4)/2; //x+y
for(int f = 3; f < 2500; f++){ int b = brown + yellow; // xy
for(int g = 1; g < 500000000; g++){ return new int[] {(int) (Math.sqrt(a*a-4*b)+a)/2, (int)(a-(Math.sqrt(a*a-4*b)+a)/2)};
if(f<g) break;
else if(brown == 2*f + 2*g - 4 && yellow == f*g - 2*f - 2* g + 4) {
answer = new int[] {f,g};
break;
}
}
if(answer.length > 0) break;
}
return answer;
} }
} }