結果
問題 | No.25 有限小数 |
ユーザー |
|
提出日時 | 2015-04-26 06:12:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 810 bytes |
コンパイル時間 | 1,345 ms |
コンパイル使用メモリ | 158,548 KB |
実行使用メモリ | 6,816 KB |
最終ジャッジ日時 | 2024-11-15 21:11:03 |
合計ジャッジ時間 | 2,130 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 WA * 1 |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long Int; #define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i)) Int gcd(Int a, Int b) { return b == 0 ? a : gcd(b, a % b); } int f(int n, int p) { int c = 0; while (n > 0 && n % p == 0) { n /= p; c++; } return c; } Int N, M; int main() { cin >> N >> M; Int g = gcd(N, M); N /= g; M /= g; Int m = M; int two = 0, five = 0; while (m > 0 && m % 2 == 0) { m /= 2; two++; } while (m > 0 && m % 5 == 0) { m /= 5; five++; } if (m != 1) { cout << -1 << endl; } else { Int ans = N; while (ans % 10 == 0) ans /= 10; ans %= 10; REP(i, two) { ans *= 5; while (ans % 10 == 0) ans /= 10; ans %= 10; } REP(i, five) { ans *= 2; while (ans % 10 == 0) ans /= 10; ans %= 10; } cout << ans << endl; } }