結果

問題 No.25 有限小数
ユーザー btkbtk
提出日時 2015-05-07 16:11:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 781 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 59,796 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 17:10:32
合計ジャッジ時間 1,195 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define LL long long
int main(void){
	LL N, M;
	cin >> N >> M;
	if (N%M == 0){
		string str = to_string(N / M);
		for (int i = (int)str.size() - 1; i >= 0; i--){
			if (str[i] != '0'){
				cout << str[i];
				break;
			}
		}
	}
	else{
		int nx, ny;
		nx = ny = 0;
		while (N % 2 == 0)N /= 2, nx++;

		while (N % 5 == 0)N /= 5, ny++;

		while (M % 2 == 0)M /= 2, nx--;

		while (M % 5 == 0)M /= 5, ny--;
	//	cout << nx << " " << ny << endl;
		if (N%M){
			cout << -1 << endl;
			return 0;
		}
		while (nx < 0 || ny < 0)nx++, ny++;
		LL res = N / M;
		res %= 10;
		LL tmp = 1;
		while (nx--){
			tmp = (tmp * 2) % 10;
		}
		if (ny>0)tmp *= 5;
		res = (res*tmp) % 10;
		cout << res << endl;
	}
	return 0;
}
0