結果

問題 No.25 有限小数
ユーザー pekempeypekempey
提出日時 2015-08-19 15:38:27
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,349 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 154,756 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-25 13:19:01
合計ジャッジ時間 8,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 162 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

map<ll, ll> primefactor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) res[n]++;
    return res;
}

ll modpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1) (res *= a) %= 10;
		(a *= a) %= 10;
		b >>= 1;
	}
	return res;
}

ll power(ll n, ll m) {
	ll res = 1;
	rep (i, m) res *= n;
	return res;
}

int main() {
	ll N, M;
	cin >> N >> M;
	ll g = __gcd(N, M);
	N /= g;
	M /= g;

	auto pf = primefactor(M);
	auto pf2 = primefactor(N);

	bool any = false;
	for (auto p : pf) {
		any |= p.first != 2 && p.first != 5;
	}

	if (any) {
		cout << -1 << endl;
		return 0;
	}

	int x = pf[2];
	int y = pf[5];

	N /= power(10, min(pf2[2], pf2[5]));

	if (x == y) {
		cout << N % 10 << endl;
	} else if (x < y) {
		ll ans = N % 10 * modpow(2, max(x, y) - x) % 10;
		cout << ans << endl;
	} else if (x > y) {
		ll ans = N % 10 * modpow(5, max(x, y) - y) % 10;
		cout << ans << endl;
	}

    return 0;
}
0