結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2016-03-03 09:03:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,175 bytes |
コンパイル時間 | 727 ms |
コンパイル使用メモリ | 84,560 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-15 21:15:43 |
合計ジャッジ時間 | 1,493 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
/* -*- coding: utf-8 -*- * * 25.cc: No.25 有限小数 - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ ll gcd(ll m, ll n) { if (m < n) swap(m, n); while (n > 0) { ll r = m % n; m = n; n = r; } return m; } /* main */ int main() { ll n, m; cin >> n >> m; ll g = gcd(m, n); m /= g; n /= g; int n2 = 0, n5 = 0; while (m % 2 == 0) m /= 2, n2++; while (m % 5 == 0) m /= 5, n5++; //printf("n2=%d, n5=%d\n", n2, n5); if (m != 1) { puts("-1"); return 0; } while (n % 10 == 0) n /= 10; int d = n % 10; while (n2 < n5) { d *= 2; while (d % 10 == 0) d /= 10; d %= 10; n2++; } while (n2 > n5) { d *= 5; while (d % 10 == 0) d /= 10; d %= 10; n5++; } printf("%d\n", d); return 0; }