結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2014-12-13 01:38:43 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 945 bytes |
コンパイル時間 | 527 ms |
コンパイル使用メモリ | 56,576 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-11 21:03:06 |
合計ジャッジ時間 | 1,365 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 WA * 1 |
ソースコード
#include<iostream> #include<cstdio> using namespace std; typedef long long int ll; #define rrep(i, m, n) for(int i=m; i<n; i++) #define rep(i, n) for(int i=0; i<n; i++) ll n, m; ll g; ll cnt[2]; ll mmin, mmax; ll res; ll x; ll gcd(ll a, ll b); int main() { cin >> n >> m; g = gcd(n, m); n /= g; m /= g; ll tmp = m; while(m%2==0){ m/=2; cnt[0]+=1; } while(m%5==0){ m/=5; cnt[1]+=1; } if(m!=1){ cout << "-1" << endl; return 0; } m = tmp; if(n%m==0){ while(n%10==0) n/=10; cout << n << endl; return 0; } if(cnt[0] > cnt[1]) x = 5; if(cnt[0] < cnt[1]) x = 2; mmax = max(cnt[0], cnt[1]); mmin = min(cnt[0], cnt[1]); res = n; rep(i, mmax-mmin) res = (res * x) % 10; cout << res%10 << endl; return 0; } ll gcd(ll a, ll b) { ll tmp; while(b){ tmp = a; a = b; b = tmp%b; } return a; }