結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2023-06-01 15:44:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,910 bytes |
コンパイル時間 | 1,509 ms |
コンパイル使用メモリ | 120,356 KB |
最終ジャッジ日時 | 2025-02-13 17:19:11 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <iostream>#include <iomanip>#include <vector>#include <algorithm>#include <functional>#include <cmath>#include <string>#include <queue>#include <map>#include <bitset>#include <set>#include <stack>#include <numeric>#include <unordered_map>#include <random>using namespace std;using ll = long long;using vi = vector<int>;using vvi = vector<vi>;using vl = vector<ll>;using vvl = vector<vl>;using vb = vector<bool>;using vvb = vector<vb>;using vd = vector<double>;using vs = vector<string>;using pii = pair<int, int>;using pll = pair<ll, ll>;using pdd = pair<double, double>;using vpii = vector<pii>;using vpll = vector<pll>;using vpdd = vector<pdd>;const int inf = (1 << 30) - 1;const ll INF = 1LL << 60;//const int MOD = 1000000007;const int MOD = 998244353;int main() {ll n, m;cin >> n >> m;bool b2 = false, b5 = false;int cnt2 = 0, cnt5 = 0;while (m % 2 == 0) {m /= 2;cnt2++;}while (m % 5 == 0) {m /= 5;cnt5++;}if (m > 1) {if (n % m == 0) {n /= m;while (n % 10 == 0) {n /= 10;}cout << n % 10 << endl;}else {cout << -1 << endl;}return 0;}if (cnt2 && cnt5) {while (n % 10 == 0) {n /= 10;}cout << n % 10 << endl;}else if (cnt2) {while (n % 2 == 0) {n /= 2;cnt2--;if (cnt2 == 0) break;}if (cnt2 == 0) {while (n % 10 == 0) {n /= 10;}cout << n % 10 << endl;}else {cout << 5 << endl;}}else {while (n % 5 == 0) {n /= 5;cnt5--;if (cnt5 == 0) break;}if (cnt5 == 0) {while (n % 10 == 0) {n /= 10;}cout << n % 10 << endl;}else {while (n % 10 == 0) {n /= 10;}int y = 2;for (int i = 1; i < cnt5; i++) {y *= 2;y %= 10;}unsigned long long x = n % 10 * y;while (x % 10 == 0) {x /= 10;}cout << x % 10 << endl;}}return 0;}