結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2017-05-08 21:39:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 829 bytes |
| コンパイル時間 | 797 ms |
| コンパイル使用メモリ | 69,888 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 17:35:42 |
| 合計ジャッジ時間 | 1,849 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long GCD(long long a, long long b) {
if (a < b) {
swap(a, b);
}
long long r = a%b;
while (r != 0)
{
a = b;
b = r;
r = a%b;
}
return b;
}
int main() {
long long N, M;
cin >> N;
cin >> M;
long long gcd = GCD(N, M);
N /= gcd;
M /= gcd;
if (N%M == 0) {
N /= M;
while (N%10==0)
{
N /= 10;
}
cout << N % 10 << endl;
return 0;
}
N %= 10;
int two = 0;
int five = 0;
while (M % 2 == 0)
{
M /= 2;
two++;
}
while (M % 5 == 0)
{
M /= 5;
five++;
}
if (M != 1) {
cout << -1 << endl;
return 0;
}
if (two > five) {
for (int i = 0; i < two - five; i++) {
N *= 5;
N %= 10;
}
} else {
for (int i = 0; i < five - two; i++) {
N *= 2;
N %= 10;
}
}
cout << N << endl;
return 0;
}
mban