結果

問題 No.25 有限小数
ユーザー bal4ubal4u
提出日時 2019-04-08 19:27:53
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 533 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 28,648 KB
実行使用メモリ 5,964 KB
最終ジャッジ日時 2023-09-14 15:44:13
合計ジャッジ時間 7,363 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.25 有限小数
// 2019.4.8 bal4u
// 有限小数の条件と求め方

#include <stdio.h>

int check(long long x)
{
	while ((x & 1) == 0) x >>= 1;
	while (x % 5 == 0) x /= 5;
	return x == 1;
}

int main()
{
	int ans;
	long long N, M;
	scanf("%lld%lld", &N, &M);
	if (!check(M)) ans = -1;
	else {
		if ((ans = (int)(N % M)) == 0) {
			N /= M;	while ((ans = (int)(N % 10)) == 0) N /= 10;
		}
		else {
			N %= M;	while (N % M) N -= (N / M) * M, N *= 10;
			ans = (int)(N / M);
		}
	}
	printf("%d\n", ans);
	return 0;
}
0