작성일 :

문제 링크

8678번 - Zbiór

설명

두 정수 a, b가 주어집니다. a의 약수 집합이 b의 약수 집합에 포함되면 TAK, 아니면 NIE를 출력합니다.

약수 포함 관계는 곧 b가 a의 배수인지 여부와 동일합니다.


접근법

먼저, b를 a로 나눈 나머지를 확인합니다. 나머지가 0이면 b는 a의 배수이므로 a의 모든 약수가 b의 약수이기도 합니다.

다음으로, 나머지가 0이 아니면 약수 집합이 포함되지 않으므로 NIE를 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.IO;

namespace Solution {
  class Program {
    static void Main(string[] args) {
      var sr = new StreamReader(Console.OpenStandardInput());
      var sw = new StreamWriter(Console.OpenStandardOutput());

      var z = int.Parse(sr.ReadLine()!);
      for (var i = 0; i < z; i++) {
        var parts = sr.ReadLine()!.Split();
        var a = int.Parse(parts[0]);
        var b = int.Parse(parts[1]);
        sw.WriteLine(b % a == 0 ? "TAK" : "NIE");
      }

      sw.Flush();
      sw.Close();
      sr.Close();
    }
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int z; cin >> z;
  while (z--) {
    int a, b; cin >> a >> b;
    cout << (b % a == 0 ? "TAK" : "NIE") << "\n";
  }

  return 0;
}