結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2016-07-30 17:31:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,204 bytes |
| コンパイル時間 | 781 ms |
| コンパイル使用メモリ | 67,200 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 21:20:00 |
| 合計ジャッジ時間 | 7,726 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 TLE * 1 |
ソースコード
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
ll GCD(ll a, ll b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
map<ll, int> PrimeFactorization(ll n) {
map<ll, int> res;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1) res[n]++;
return res;
}
int main() {
ll N, M, gcd;
cin >> N >> M;
gcd = GCD(N, M);
N /= gcd;
M /= gcd;
map<ll, int> factors = PrimeFactorization(M);
int exp2 = 0, exp5 = 0;
for (auto it = factors.begin(); it != factors.end(); it++) {
if (it->first == 2) {
exp2 = it->second;
} else if (it->first == 5) {
exp5 = it->second;
} else {
cout << -1 << endl;
return 0;
}
}
// 確実に下一桁が0以外の数字にするために
while (N % 10 == 0) {
N /= 10;
}
for (int i = 0; i < max(exp2, exp5) - exp2; i++) {
N = (N * 2) % 10;
}
for (int i = 0; i < max(exp2, exp5) - exp5; i++) {
N = (N * 5) % 10;
}
cout << (N % 10) << endl;
return 0;
}
ふーらくたる