結果

問題 No.25 有限小数
ユーザー h_noson
提出日時 2016-05-03 18:29:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 816 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 59,868 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 21:16:36
合計ジャッジ時間 1,361 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int i;
    ull n, m;
    cin >> n >> m;
    ll d = __gcd(n,m);
    n /= d;
    m /= d;
    while (n % 10 == 0) n /= 10;
    while (m % 10 == 0) m /= 10;
    n %= 10;
    while (m % 2 == 0 || m % 5 == 0) {
        if (m % 2 == 0) {
            n = n * 5 % 10;
            m /= 2;
        }
        if (m % 5 == 0) {
            n = n * 2 % 10;
            m /= 5;
        }
    }
    if (m == 1)
        cout << n << endl;
    else
        cout << -1 << endl;
    return 0;
}
0