結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-19 15:42:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 992 bytes |
| コンパイル時間 | 1,539 ms |
| コンパイル使用メモリ | 159,420 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 21:12:51 |
| 合計ジャッジ時間 | 2,122 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#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;
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;
}
int main() {
ll N, M;
cin >> N >> M;
ll g = __gcd(N, M);
N /= g;
M /= g;
int x = 0;
int y = 0;
while (M % 2 == 0) {
x++;
M /= 2;
}
while (M % 5 == 0) {
y++;
M /= 5;
}
while (N % 10 == 0) {
N /= 10;
}
if (M != 1) {
cout << -1 << endl;
return 0;
}
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;
}