입력 횟수 만큼 반복하면서 최소공배수를 구해서 출력해주면 되는 문제이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
namespace 연습장
{
internal class Program
{
static void Main(string[] args)
{
using var reader = new StreamReader(Console.OpenStandardInput());
using var print = new StreamWriter(Console.OpenStandardOutput());
StringBuilder sb = new StringBuilder();
int T = int.Parse(reader.ReadLine());
for (int i = 0; i < T; i++)
{
int[] arr = Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
int A = Math.Min(arr[0], arr[1]);
int B = Math.Max(arr[0], arr[1]);
int temp = EcA(A, B);
int res = A / temp * B / temp * temp;
print.WriteLine(res);
}
}
static int EcA(int A, int B)
{
int temp = int.MaxValue;
while (temp != 0)
{
temp = B % A;
B = A;
A = temp;
}
return B;
}
}
}
|
cs |
이번에는 유클리드 호제법 파트를 따로 메서드로 빼줬다. 훨씬 보기 좋은거 같다.
'하루 한 접시' 카테고리의 다른 글
[백준] 4134번: 다음 소수 [C#] (0) | 2024.03.30 |
---|---|
[백준] 2485번: 가로수 [c#] (0) | 2024.03.29 |
[백준] 13241번: 최소공배수 [C#] (0) | 2024.03.28 |
[백준] 1735 분수 합 [C#] (0) | 2024.03.28 |
[백준] 1269번 대칭 차집합 [C#] (0) | 2024.03.27 |