QOJ.ac

QOJ

时间限制: 1 s 内存限制: 32 MB 总分: 10

#11674. 循环数

统计

设 $k$ 为给定的正整数,$A$ 为一个十进制表示由 $k$ 位数字组成的正整数(允许最高位为 $0$)。若两个数 $A = (a_1, a_2, \dots, a_k)_{10}$ 和 $B = (b_1, b_2, \dots, b_k)_{10}$(其中第 $k$ 位为最低位,第 $1$ 位为最高位)满足存在 $1 \le l \le k$ 使得:

$$(a_1, a_2, \dots, a_k)_{10} = (b_l, b_{l+1}, \dots, b_k, b_1, b_2, \dots, b_{l-1})_{10}$$

即 $A$ 的值等于 $B$ 的数字循环左移 $l-1$ 位后的值,则称 $A$ 与 $B$ 循环相等。若一个 $k$ 位数 $A$ 满足集合 $\{1 \cdot A, 2 \cdot A, \dots, k \cdot A\}$ 中的所有数都循环相等,则称 $A$ 为循环数。循环数 $A$ 的族定义为所有数 $1 \cdot A, 2 \cdot A, \dots, k \cdot A$ 的集合。

题目描述

编写一个程序:

  • 读取一个正整数 $n$。
  • 对于给定的 $n$,找出最小的整数 $B \ge n$,使得存在某个 $k \ge 1$,满足 $B$ 属于某个 $k$ 位循环数 $A$ 的族,或者判定不存在这样的 $B$。
  • 输出计算出的 $B$,如果不存在这样的数,则输出 BRAK

输入格式

输入的第一行包含一个自然数 $n$,$1 \le n \le 10^{17}$。

输出格式

输出的第一行应包含一个整数 $B$——即问题的解,如果不存在这样的数,则输出 BRAK

样例

样例输入 1

428571

样例输出 1

428571

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.