結果
問題 | No.25 有限小数 |
ユーザー | drymouse |
提出日時 | 2024-02-17 23:11:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,146 bytes |
コンパイル時間 | 634 ms |
コンパイル使用メモリ | 69,176 KB |
実行使用メモリ | 10,004 KB |
最終ジャッジ日時 | 2024-02-17 23:12:04 |
合計ジャッジ時間 | 7,790 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,676 KB |
testcase_01 | AC | 2 ms
6,676 KB |
testcase_02 | AC | 2 ms
6,676 KB |
testcase_03 | AC | 2 ms
6,676 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
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 | -- | - |
ソースコード
#include <iostream> using namespace std; long long long_gcd(long long a, long long b) { if (a < b) { long long x = a; a = b; b = x; } long long r; for (;b > 0;){ r = a % b; a = b; b = r; } return a; } int last_dig(long long a) { if (a == 0) {return 0;} for (;a % 10 == 0;) { a /= 10; } return a % 10; } int main(void) { long long N, M; cin >> N >> M; long long daiyaku = long_gcd(N, M); long long nshou = N / daiyaku; long long mshou = M / daiyaku; if (mshou == 1) { cout << last_dig(nshou) << endl; return 0; } for (long long i = 3; i < mshou + 1; i+=2) { if (i % 5 == 0) { continue;; } else if (mshou % i == 0) { cout << -1 << endl; return 0; } } long long digit = nshou % mshou; for (;mshou % 2 == 0;) { digit *= 5; mshou /= 2; } digit = last_dig(digit); for (;mshou % 5 == 0;) { digit <<= 1; mshou /= 5; } digit = last_dig(digit); cout << digit << endl; return 0; }