結果

問題 No.1047 Zero (Novice)
ユーザー kekenx
提出日時 2024-01-09 16:12:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 481 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 66,300 KB
最終ジャッジ日時 2025-02-18 16:47:35
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 16 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  long long A, B; cin >> A >> B;
  long long N = B;
  long long P = 1e18;
  long long PP = 1e18;
  for (int i = 1; i < 1e7; i++) {
    N = A * N + B;
    if (abs(N) > abs(PP)) {
      cout << -1 << endl;
      return 0;
    }
    if (N == 0) {
      cout << i << endl;
      return 0;
    }
    PP = P;
    P = N;
  }
  cout << -1 << endl;
  return 0;
}
0