結果

問題 No.1047 Zero (Novice)
ユーザー CELICA
提出日時 2020-07-01 10:24:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 475 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 170,820 KB
実行使用メモリ 250,752 KB
最終ジャッジ日時 2024-09-13 20:53:49
合計ジャッジ時間 5,138 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

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

    ll a,b,n{0};
    cin >> a >> b;

    set<ll> s;
    
    int cnt{0};
    while (1)
    {
        n=a*n+b;
        ++cnt;
        if (!n)
            break;
        if (s.find(n)!=s.end())
        {
            cout << "-1\n";
            return 0;
        }
        s.insert(n);
    }

    cout << cnt << "\n";
    
    return 0;
}
0