結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2022-12-19 21:52:58 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 969 bytes |
コンパイル時間 | 1,689 ms |
コンパイル使用メモリ | 143,336 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-18 01:25:45 |
合計ジャッジ時間 | 1,660 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <iostream> #include <vector> #include <cmath> #include <map> #include <set> #include <iomanip> #include <queue> #include <algorithm> #include <numeric> #include <deque> #include <complex> using namespace std; int main(){ long long N, M, g, X, cnt2=0, cnt5=0, s; cin >> N >> M; g = gcd(N, M); N /= g; M /= g; if (N % M == 0){ X = N/M; while(X != 0){ if (X % 10 != 0){ cout << X % 10 << endl; return 0; } X /= 10; } } while(M % 2 == 0){ cnt2++; M /= 2; } while(M % 5 == 0){ cnt5++; M /= 5; } if (M != 1){ cout << -1 << endl; return 0; } while (N % 10 == 0) N /= 10; s = N % 10; while(cnt5 > cnt2){ s = s*2 % 10; cnt2++; } while(cnt2 > cnt5){ s = s*5 % 10; cnt5++; } cout << s << endl; return 0; }