結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2016-09-22 21:31:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 888 bytes |
コンパイル時間 | 776 ms |
コンパイル使用メモリ | 79,700 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 13:12:08 |
合計ジャッジ時間 | 1,699 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <iostream> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <iomanip> #include <cmath> #include <cassert> using namespace std; typedef long long ll; ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; ll g = gcd(N, M); N /= g, M /= g; if(M == 1) { while(N % 10 == 0) N /= 10; cout << N % 10 << endl; return 0; } int t = 0, f = 0; ll m = M; while(m % 2 == 0) { m /= 2; t++; } while(m % 5 == 0) { m /= 5; f++; } if(m != 1) { cout << -1 << endl; return 0; } if(t > f) { for(int i = 0; i < t - f; i++) { N *= 5; N %= 1000000; while(N % 10 == 0) N /= 10; } } else { for(int i = 0; i < f - t; i++) { N *= 2; N %= 1000000; while(N % 10 == 0) N /= 10; } } cout << N % 10 << endl; }