結果

問題 No.25 有限小数
ユーザー hotpepsi
提出日時 2015-05-08 00:08:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 638 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 65,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 20:08:03
合計ジャッジ時間 1,256 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <set>
#include <vector>

using namespace std;
typedef long long LL;

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

int main(int argc, char *argv[]) {
	LL N, M;
	string s;
	getline(cin, s);
	stringstream sa(s);
	sa >> N;
	getline(cin, s);
	stringstream sb(s);
	sb >> M;
	LL g = gcd(N, M);
	LL a = N / g, b = M / g;
	while ((a % 10) == 0) {
		a /= 10;
	}
	a = a % 10;
	while ((b % 2) == 0) {
		a = (a * 5) % 10;
		b /= 2;
	}
	while ((b % 5) == 0) {
		a = (a * 2) % 10;
		b /= 5;
	}
	LL ans = b == 1 ? a : -1;
	cout << ans << endl;
	return 0;
}
0