問題一覧 > 通常問題

No.1047 Zero (Novice)

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 380
作問者 : stoq / テスター : trineutron
お気に入りにしたユーザー ProblemId : 4134 / 自分の提出
問題文最終更新日: 2020-05-07 17:14:41
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 247 (順位表) の他の問題:

Problem Statement

S-kun has an integer $N$. Initially, $N=0$.
S-kun performs the following operation any number of times, at least once.

・Replace $N$ with $AN+B$.

Can $N=0$ hold again after some number of operations? If it can, output the minimum number of operations; otherwise, output -1.

Input

$A\ B$

$A,B$ are integers.
$-10^9 \leq A,B \leq 10^9$

Output

If $N=0$ can hold again after some number of operations, output the minimum number of operations; otherwise, output -1.
Print a newline at the end.

Sample

Sample 1
Input
-1 2
Output
2

The first operation gives $N=-1 \cdot 0 +2 = 2$,
and the second operation gives $N=-1 \cdot 2 +2 = 0$.
Therefore, the minimum number of operations is 2.

Sample 2
Input
10 10
Output
-1

$N=0$ never holds again.

Sample 3
Input
1 0
Output
1

The first operation gives $N=1 \cdot 0 +0 = 0$.
Therefore, the minimum number of operations is 1.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。