結果

問題 No.25 有限小数
ユーザー hogeover30
提出日時 2015-02-25 12:33:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 548 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 71,436 KB
実行使用メモリ 394,940 KB
最終ジャッジ日時 2024-06-23 23:15:56
合計ジャッジ時間 8,153 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 1 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
int main()
{
    long long n, m;
    while (cin>>n>>m) {
        unordered_set<long long> s;
        auto res=-1LL;
        while (true) {
            auto t=n%m;
            if (!t) {
                n/=m;
                while (n%10==0) n/=10;
                res=n%10;
                break;
            }
            if (s.count(t)) { res=-1; break; }
            s.insert(t);
            n%=m;
            n*=10;
        }
        cout<<res<<endl;
    }
}
0