結果

問題 No.25 有限小数
ユーザー h_noson
提出日時 2016-05-03 18:27:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 59,680 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-05 04:50:45
合計ジャッジ時間 1,222 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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;
    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