結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-24 02:59:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,366 bytes |
| コンパイル時間 | 1,166 ms |
| コンパイル使用メモリ | 124,964 KB |
| 最終ジャッジ日時 | 2025-01-21 00:36:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 TLE * 1 |
ソースコード
#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;
}