結果

問題 No.25 有限小数
ユーザー snrnsidysnrnsidy
提出日時 2021-04-24 02:59:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,366 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 128,524 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-09-17 13:22:10
合計ジャッジ時間 8,100 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 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 #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>

using namespace std;

unsigned long long int gcd(unsigned long long int a, unsigned long long int b)
{
	if (b == 0)
	{
		return a;
	}
	return gcd(b, a % b);
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	unsigned long long int N, M;

	cin >> N >> M;

	unsigned long long int g = gcd(N, M);
	N /= g;
	M /= g;
	
	unsigned long long int temp = M;

	while (1)
	{
		if (temp % 2 != 0)
		{
			break;
		}
		temp /= 2;
	}
	while (1)
	{
		if (temp % 5 != 0)
		{
			break;
		}
		temp /= 5;
	}
	if (temp > 1)
	{
		cout << -1 << '\n';
		return 0;
	}
	

	unsigned long long int res = 0;
	unsigned long long int XX = N / M;
	while (XX > 0)
	{
		if (XX % 10 != 0)
		{
			res = XX % 10;
			break;
		}
		XX /= 10;
	}
	N %= M;
	while (1)
	{
		if (N == 0)
		{
			break;
		}
		N *= 10;
		unsigned long long int a = N / M;
		N %= M;
		//cout << N << ' ' << a << '\n';
		res = a;
	}
	cout << res << '\n';

	return 0;
}
0