B. Ugly Number

Codeforces
IDCF10187B
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
A k-cyclic shift of an integer x is a function that removes the last k digits of x and inserts them in its beginning. For example, the k-cyclic shifts of 123 are 312 for k = 1 and 231 for k = 2. Teo, a kid from Canada, learned from his Canadian friends this definition of ugly numbers: a number is ugly if, and only if every one of its k-cyclic shifts returns a number greater than or equal to it. Given an n-digit decimal number x, can you answer if it is ugly or not? The first line of the input contains a single integer n (1 ≤ n ≤ 5 × 105), indicating the number of digits of the number. The next line contains an n-digit decimal number, indicating the value of x. Output "Yes" if x is an ugly number and "No" otherwise. ## Input The first line of the input contains a single integer n (1 ≤ n ≤ 5 × 105), indicating the number of digits of the number.The next line contains an n-digit decimal number, indicating the value of x. ## Output Output "Yes" if x is an ugly number and "No" otherwise. [samples]
**Definitions** Let $ N \in \mathbb{Z}^+ $ be the number of verses. Let $ L = (\ell_1, \ell_2, \dots, \ell_N) $ be a sequence of positive integers representing verse sizes. For $ K \in \mathbb{Z} $, $ K > 1 $, define the remainder distribution: $ r_K(i) = \left| \left\{ j \in \{1, \dots, N\} \mid \ell_j \equiv i \pmod{K} \right\} \right| $ for $ i = 0, 1, \dots, K-1 $. The poem is $ K $-elegant if: 1. $ K > 1 $, 2. $ K \mid N $, 3. $ r_K(i) = \frac{N}{K} $ for all $ i \in \{0, 1, \dots, K-1\} $. **Objective** Find the smallest integer $ K > 1 $ such that the poem is $ K $-elegant. If no such $ K $ exists, output $-1$.
API Response (JSON)
{
  "problem": {
    "name": "B. Ugly Number",
    "description": {
      "content": "A k-cyclic shift of an integer x is a function that removes the last k digits of x and inserts them in its beginning. For example, the k-cyclic shifts of 123 are 312 for k = 1 and 231 for k = 2. Teo,",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10187B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A k-cyclic shift of an integer x is a function that removes the last k digits of x and inserts them in its beginning. For example, the k-cyclic shifts of 123 are 312 for k = 1 and 231 for k = 2.\n\nTeo,...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the number of verses.  \nLet $ L = (\\ell_1, \\ell_2, \\dots, \\ell_N) $ be a sequence of positive integers representing verse sizes.  \n\nFor $ K \\in \\mathbb{...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments