Skip to content

Commit df45b94

Browse files
committed
[Math] baekjoon-21275
1 parent b89b001 commit df45b94

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

โ€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
| # | โ˜† | Problem | Note |
290290
| :-: | :-: | :--------------------------------------------- | :----- |
291291
| 01 | | [Baekjoon-13458 ์‹œํ—˜ ๊ฐ๋…](./src/Math/P13458) | |
292+
| 02 | | [Baekjoon-21275 ํฐ ํ˜ธ์„๋งŒ](./src/Math/P21275) | ์™„์ „ํƒ์ƒ‰ |
292293

293294
## Number Theory
294295

โ€Žsrc/Math/P21275/Main.java

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package Math.P21275;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileInputStream;
5+
import java.io.InputStreamReader;
6+
import java.util.StringTokenizer;
7+
8+
public class Main {
9+
10+
static long X;
11+
static int A, B;
12+
static int[] n1, n2;
13+
14+
public static void main(String[] args) throws Exception {
15+
System.setIn(new FileInputStream("src/Math/P21275/input.txt"));
16+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
19+
String s1 = st.nextToken(), s2 = st.nextToken();
20+
21+
n1 = new int[s1.length()];
22+
n2 = new int[s2.length()];
23+
int A_min = 0, B_min = 0;
24+
25+
for (int i = 0, size = s1.length(); i < size; i++) {
26+
char c = s1.charAt(size-i-1);
27+
n1[i] = (c >= 'a') ? c - 'a' + 10 : c - '0';
28+
A_min = Math.max(A_min, n1[i]+1);
29+
}
30+
for (int i = 0, size = s2.length(); i < size; i++) {
31+
char c = s2.charAt(size-i-1);
32+
n2[i] = (c >= 'a') ? c - 'a' + 10 : c - '0';
33+
B_min = Math.max(B_min, n2[i]+1);
34+
}
35+
36+
int cnt = 0;
37+
loop:
38+
for (int a = A_min; a <= 36; a++) {
39+
long X1 = 0, a_ = 1;
40+
for (int i = 0, size = s1.length(); i < size; i++) {
41+
X1 += n1[i] * a_;
42+
a_ *= a;
43+
}
44+
for (int b = B_min; b <= 36; b++) {
45+
if (a == b) continue;
46+
long X2 = 0, b_ = 1;
47+
for (int i = 0, size = s2.length(); i < size; i++) {
48+
X2 += n2[i] * b_;
49+
b_ *= b;
50+
}
51+
52+
if (X1 >= 0 && X1 == X2) {
53+
X = X1;
54+
A = a;
55+
B = b;
56+
if (++cnt > 1) break loop;
57+
}
58+
}
59+
}
60+
61+
if (cnt == 1) System.out.println(X + " " + A + " " + B);
62+
else if (cnt > 1) System.out.println("Multiple");
63+
else System.out.println("Impossible");
64+
}
65+
}

โ€Žsrc/Math/P21275/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## [baekjoon-21275] ํฐ ํ˜ธ์„๋งŒ
2+
3+
![image](https://user-images.githubusercontent.com/22045163/113019073-2b398080-91bc-11eb-9eae-a3a1001796d0.png)
4+
5+
์ฃผ์–ด์ง„ ๋ฒ”์œ„๋ฅผ ๋†“๊ณ  ๊ณ„์‚ฐํ•ด๋ณด๋ฉด ์™„์ „ ํƒ์ƒ‰์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๋‹ˆ ๊ฒ๋จน์„ ํ•„์š” ์—†๋‹ค.
6+
7+
![image](https://user-images.githubusercontent.com/22045163/113019102-342a5200-91bc-11eb-9833-1f567cac7596.png)

โ€Žsrc/Math/P21275/input.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2222222222222222222222222222222222222222222222222222222222222222222222 8888888888888888888888888888888

0 commit comments

Comments
ย (0)