結果
問題 |
No.25 有限小数
|
ユーザー |
![]() |
提出日時 | 2016-05-05 20:36:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,687 bytes |
コンパイル時間 | 583 ms |
コンパイル使用メモリ | 81,124 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-05 09:57:02 |
合計ジャッジ時間 | 1,516 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 WA * 9 |
ソースコード
//#include <bits/stdc++.h> #include <assert.h> #include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <iterator> using namespace std; typedef signed long long ll; #define pp(...) (void)printf(__VA_ARGS__) #define For(x,to) for(x=0;x<(to);x++) #define ForAuto(x,arr) for(auto& x:arr) #define ForBeginEnd(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define All(a) (a.begin()),(a.end()) #define Zeros(a) memset(a,0,sizeof(a)) #define Minus(a) memset(a,0xff,sizeof(a)) #define PI 3.14159265 #define EPS (1e-10) #define EPS_eq(a,b) (abs((a)-(b)) < EPS) #pragma GCC diagnostic ignored "-Wconversion" //#define int long long const int INF = 1000*1000; int dxy[] = {0, 1, 0, -1, 0}; typedef pair<int, int> P; void pp_int(int x){ printf("%d\n", x); }; //------------------------------------------------- signed main() { ll n,m;cin>>n>>m; ll gcd = __gcd(n,m); n /= gcd; m /= gcd; if(n % m == 0){ ll res = n/m; while(res % 10 == 0){ res /= 10; } printf("%lld\n", res % 10); return 0; } ll m5 = 0, m2 = 0; while(m % 2 == 0) m /= 2, m2++; while(m % 5 == 0) m /= 5, m5++; if (m != 1) { printf("-1\n"); return 0; } while(n % 10==0)n/=10; while(m2 > m5){ m5++; n *= 5; while(n % 10==0)n/=10; } while(m2 < m5){ m2++; n *= 2; while(n % 10==0)n/=10; } while(n % 10==0)n/=10; printf("%lld\n", n % 10); return 0; }