結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2016-09-22 21:33:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 800 bytes |
コンパイル時間 | 904 ms |
コンパイル使用メモリ | 78,416 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 13:12:48 |
合計ジャッジ時間 | 1,512 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; } while(t != f) { if(t > f) { N *= 5; t--; } else { N *= 2; f--; } N %= 1000000; while(N % 10 == 0) N /= 10; } cout << N % 10 << endl; }