結果

問題 No.25 有限小数
ユーザー furonfuron
提出日時 2023-06-01 15:38:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,786 bytes
コンパイル時間 1,167 ms
コンパイル使用メモリ 123,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 02:05:04
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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) {
		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 * y;
			while (x % 10 == 0) {
				x /= 10;
			}
			cout << x % 10 << endl;
		}
	}

	return 0;
}
0