結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2015-05-07 16:11:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 781 bytes |
コンパイル時間 | 452 ms |
コンパイル使用メモリ | 58,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-15 21:11:05 |
合計ジャッジ時間 | 1,345 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include<iostream> #include<algorithm> #include<string> using namespace std; #define LL long long int main(void){ LL N, M; cin >> N >> M; if (N%M == 0){ string str = to_string(N / M); for (int i = (int)str.size() - 1; i >= 0; i--){ if (str[i] != '0'){ cout << str[i]; break; } } } else{ int nx, ny; nx = ny = 0; while (N % 2 == 0)N /= 2, nx++; while (N % 5 == 0)N /= 5, ny++; while (M % 2 == 0)M /= 2, nx--; while (M % 5 == 0)M /= 5, ny--; // cout << nx << " " << ny << endl; if (N%M){ cout << -1 << endl; return 0; } while (nx < 0 || ny < 0)nx++, ny++; LL res = N / M; res %= 10; LL tmp = 1; while (nx--){ tmp = (tmp * 2) % 10; } if (ny>0)tmp *= 5; res = (res*tmp) % 10; cout << res << endl; } return 0; }