結果

問題 No.25 有限小数
ユーザー myantamyanta
提出日時 2017-05-03 00:39:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 26,768 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 05:20:00
合計ジャッジ時間 1,296 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>


using ll=long long;
using ull=unsigned long long;


ull gcd(ull a, ull b)
{
	ull c;
	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


void com_div(ull& a, ull& b)
{
	ull d=gcd(a, b);
	a/=d;
	b/=d;
}


int main(void)
{
	ull n, m, t;
	int c2, c5;

	while(scanf("%llu%llu", &n, &m)==2)
	{
		com_div(n, m);

		t=m;
		for(c2=0;t%2==0;t/=2) c2++;
		for(c5=0;t%5==0;t/=5) c5++;

		if(t!=1)
		{
			printf("-1\n");
			continue;
		}
		if(c2>c5)
		{
			printf("5\n");
			continue;
		}

		for(;n%10==0;n/=10);
		n%=10;
		for(int i=c5-c2;i>0;i--) n=(n*2)%10;

		printf("%d\n", (int)n);
	}

	return 0;
}
0