結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2015-06-25 03:03:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,680 bytes |
コンパイル時間 | 673 ms |
コンパイル使用メモリ | 88,052 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-15 21:11:12 |
合計ジャッジ時間 | 1,577 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cstdlib> // require abs exit atof atoi #include <cstdio> // require scanf printf #include <functional> #include <numeric> // require accumulate #include <cmath> // require fabs #include <climits> #include <limits> #include <cfloat> #include <iomanip> // require setw #include <sstream> // require stringstream #include <cstring> // require memset #include <cctype> // require tolower, toupper #include <fstream> // require freopen #include <ctime> // require srand #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() /* No.25 有限小数 http://yukicoder.me/problems/70 */ using namespace std; typedef long long ll; typedef pair<int, int> P; const int mod2[] = { 2, 4, 8, 6 }; int main() { ios_base::sync_with_stdio(0); ll N, M; cin >> N >> M; ll g = __gcd (N, M ); N /= g; M /= g; if (M != 1LL && N > M ){ N = N - (N/M)*M; } // end if int two = 0, five = 0; while (M % 2LL == 0 ) M /= 2LL, two++; while (M % 5LL == 0 ) M /= 5LL, five++; // cerr << "N: " << N << " M: " << M << " g: " << g << endl; ll res = 1LL; if (two > five ){ // 2 の方が多いなら分母、分子に5の倍数を掛けて小数表示化する x/10^n res = 5; }else if (two < five ){ res = mod2[(five - two - 1 + 4 ) % 4]; } // end if while (N > 0 && (N % 10LL ) == 0 ) N /= 10LL; res = (res * (N % 10LL ) ) % 10LL; if (M != 1LL ){ cout << -1 << endl; }else{ cout << res << endl; } // end if return 0; }