結果

問題 No.1047 Zero (Novice)
ユーザー kyo1kyo1
提出日時 2020-05-20 10:14:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 493 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 199,464 KB
実行使用メモリ 142,876 KB
最終ジャッジ日時 2024-04-09 22:51:25
合計ジャッジ時間 5,578 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t A, B;
  cin >> A >> B;
  if (A * B > 0 || A == -B) {
    cout << -1 << '\n';
  } else {
    int64_t N = B;
    int res = 1;
    set<int64_t> st;
    st.insert(N);
    while (N != 0) {
      N = N * A + B;
      if (st.find(N) != st.end()) {
        cout << -1 << '\n';
        return 0;
      }
      st.insert(N);
      res++;
    }
    cout << res << '\n';
  }
  return 0;
}
0