B. Friendly Numbers

Codeforces
IDCF100B
Time2000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
Kiana thinks two integers are friends if and only if one of them divides the other one. For example, 12 and 4 are friends, also 6 and 6 are friends too, but 120 and 36 are not. A group of non-zero integers is called friendly, if each pair of its integers form a friend pair. You are given a group of non-zero integers. See if they're friendly. ## Input The first line contains _n_ (1 ≤ _n_ ≤ 1000), where _n_ — the number of integers in the group. The next line contains the elements, sorted in the non-decreasing order. The numbers are comma separated, they have at most 7 digits in their decimal notation and do not have any leading zeros. ## Output If the group is friendly write "_FRIENDS_", else write "_NOT FRIENDS_". [samples]
Kiana 认为两个整数是朋友,当且仅当其中一个能整除另一个。例如,12 和 4 是朋友,6 和 6 也是朋友,但 120 和 36 不是。 一组非零整数被称为友好的,当且仅当其中每一对整数都构成朋友对。 给定一组非零整数,请判断它们是否友好。 第一行包含 #cf_span[n](#cf_span[1 ≤ n ≤ 1000]),其中 #cf_span[n] 表示该组中整数的个数。 第二行包含按非递减顺序排列的元素,数字以逗号分隔,每个数的十进制表示最多有 7 位数字,且没有前导零。 如果该组是友好的,请输出 "_FRIENDS_",否则输出 "_NOT FRIENDS_"。 ## Input 第一行包含 #cf_span[n](#cf_span[1 ≤ n ≤ 1000]),其中 #cf_span[n] 表示该组中整数的个数。第二行包含按非递减顺序排列的元素,数字以逗号分隔,每个数的十进制表示最多有 7 位数字,且没有前导零。 ## Output 如果该组是友好的,请输出 "_FRIENDS_",否则输出 "_NOT FRIENDS_"。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ with $ 1 \leq n \leq 1000 $ be the number of integers. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of non-zero integers, sorted in non-decreasing order, with $ |a_i| \leq 10^7 $ for all $ i $. **Constraints** For all $ i \in \{1, \dots, n\} $, $ a_i \neq 0 $ and $ a_i \in \mathbb{Z} $. **Objective** Determine whether for all pairs $ (i, j) $ with $ 1 \leq i < j \leq n $, either $ a_i \mid a_j $ or $ a_j \mid a_i $. If yes, output "_FRIENDS_"; otherwise, output "_NOT FRIENDS_".
Samples
Input #1
4
1,3,6,12
Output #1
FRIENDS
Input #2
3
1,2,9
Output #2
NOT FRIENDS
API Response (JSON)
{
  "problem": {
    "name": "B. Friendly Numbers",
    "description": {
      "content": "Kiana thinks two integers are friends if and only if one of them divides the other one. For example, 12 and 4 are friends, also 6 and 6 are friends too, but 120 and 36 are not. A group of non-zero in",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF100B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Kiana thinks two integers are friends if and only if one of them divides the other one. For example, 12 and 4 are friends, also 6 and 6 are friends too, but 120 and 36 are not.\n\nA group of non-zero in...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Kiana 认为两个整数是朋友,当且仅当其中一个能整除另一个。例如,12 和 4 是朋友,6 和 6 也是朋友,但 120 和 36 不是。\n\n一组非零整数被称为友好的,当且仅当其中每一对整数都构成朋友对。\n\n给定一组非零整数,请判断它们是否友好。\n\n第一行包含 #cf_span[n](#cf_span[1 ≤ n ≤ 1000]),其中 #cf_span[n] 表示该组中整数的个数。\n\n第二行包...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ with $ 1 \\leq n \\leq 1000 $ be the number of integers.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of non-zero integers, sorted in non-decreasing orde...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments