結果
問題 | No.25 有限小数 |
ユーザー |
|
提出日時 | 2015-08-19 15:38:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,349 bytes |
コンパイル時間 | 1,275 ms |
コンパイル使用メモリ | 167,408 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-07-18 10:30:29 |
合計ジャッジ時間 | 14,145 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 TLE * 2 -- * 12 |
ソースコード
#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; }