結果

問題 No.25 有限小数
ユーザー snrnsidy
提出日時 2021-04-24 02:53:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,218 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 125,340 KB
最終ジャッジ日時 2025-01-21 00:36:41
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 1 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

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;

long long int gcd(long long int a, 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);
	
	long long int N, M;

	cin >> N >> M;

	long long int g = gcd(N, M);
	N /= g;
	M /= g;
	
	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;
	}
	if (M == 1)
	{
		cout << 1 << '\n';
		return 0;
	}

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

	return 0;
}
0