結果

問題 No.25 有限小数
ユーザー Kutimoti_T
提出日時 2017-12-18 21:10:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 582 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 56,160 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-12-16 00:34:11
合計ジャッジ時間 118,414 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 6 TLE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

typedef long long ll;

ll N;
ll M;

int twoans[] = {2,4,8,6};


int main()
{
	cin >> N >> M;
	
	for(ll i = 2;i < N && i < M;i++)
	{
		if(N % i == 0 && M % i == 0)
		{
			N /= i;
			M /= i;
			i--;
		}
	}
	int two = 0;
	int five = 0;
	while(M % 2 == 0)
	{
		M /= 2;
		two++;
	}
	while(M % 5 == 0)
	{
		M /= 5;
		five++;
	}
	if(M == 1)
	{
		if(two <  five)
		{
			cout << (N * twoans[(five - two - 1) % 4]) % 10 << endl;
		}
		else
		{
			cout << (N * 5 * (two - five)) % 10 << endl;
		}
	}
	else
	{
		cout << -1 << endl;
	}
	return 0;
			
}
0