結果

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

ソースコード

diff #

#include <algorithm>
#include <iostream>

using namespace std;

long long N, M;

int main() {
	cin >> N >> M;
	long long gcd = __gcd(N, M);
	N /= gcd; M /= gcd;
	int cnt2 = 0, cnt5 = 0;
	while (M % 2 == 0) {
		cnt2++;
		M /= 2;
	}
	while (M % 5 == 0) {
		cnt5++;
		M /= 5;
	}
	while (N % 10 == 0) {
		N /= 10;
	}
	N %= 10;
	if (M > 1) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < cnt5 - cnt2; i++) {
			N *= 2;
			N %= 10;
		}
		for (int i = 0; i < cnt2 - cnt5; i++) {
			N *= 5;
			N %= 10;
		}
		cout << N << endl;
	}
	return 0;
}
0