結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2019-04-16 13:22:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 790 bytes |
コンパイル時間 | 671 ms |
コンパイル使用メモリ | 84,704 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 08:14:40 |
合計ジャッジ時間 | 1,736 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <unordered_map> using namespace std; typedef long long int ll; typedef pair<int, int> P; ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b); } int main() { ll n, m; cin>>n>>m; ll d=gcd(n, m); n/=d, m/=d; ll m1=m; while(m1%2==0) m1/=2; while(m1%5==0) m1/=5; if(m1>1){ cout<<-1<<endl; return 0; } while(m%10==0) m/=10; if(m==1){ while(n%10==0) n/=10; cout<<n%10<<endl; return 0; } if(m%2==0){ cout<<5<<endl; return 0; } n%=10; while(m>1){ m/=5; n*=2; n%=10; } cout<<n<<endl; return 0; }