結果

問題 No.25 有限小数
ユーザー togari_takamoto
提出日時 2016-02-25 23:07:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 608 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 158,440 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-15 21:15:34
合計ジャッジ時間 2,179 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define REP(i,n) for(ll i=0; i<(n); ++i)

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	ll _n, _m;
	cin >> _n >> _m;

	ll x = gcd(_n, _m);
	ll n = _n / x, m = _m / x;

	ll i_5 = 0;
	while (m % 5 == 0) { i_5++; m /= 5; }
	ll i_2 = 0;
	while (m % 2 == 0) { i_2++; m /= 2; }

	if (m!=1) {
		cout << -1 << endl;
	} else if (i_5 != i_2) {
		n %= 10;
		REP(i, abs(i_2 - i_5)) {
			(n *= (i_5 < i_2 ? 5 : 2)) %= 10;
		}
		cout << n << endl;
	} else {
		while (n % 10 == 0) n /= 10;
		cout << n % 10 << endl;
	}

	return 0;
}
0