結果

問題 No.25 有限小数
ユーザー ふーらくたる
提出日時 2016-07-30 16:37:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 541 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 64,952 KB
実行使用メモリ 188,064 KB
最終ジャッジ日時 2024-11-06 21:19:01
合計ジャッジ時間 9,023 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 1 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <string>
using namespace std;

typedef long long ll;

int main() {
    ll N, M;
    int ans = 0;
    set<ll> recorder;
    cin >> N >> M;

    while (N != 0) {
        if (recorder.find(N) != recorder.end()) {
            cout << -1 << endl;
            return 0;
        }
        recorder.insert(N);
        string str = to_string(N / M);
        for (auto ch : str) {
            if (ch != '0') ans = ch - '0';
        }
        N = (N % M) * 10;
    }
    cout << ans << endl;
    return 0;
}
0