結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-21 16:02:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 553 bytes |
| コンパイル時間 | 4,392 ms |
| コンパイル使用メモリ | 250,500 KB |
| 最終ジャッジ日時 | 2025-01-28 10:55:02 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
ll n,m;
void solve(){
ll g = gcd(n,m);
n/=g;
m/=g;
ll M = m;
int t = 0,f = 0;
while(M%5==0)M/=5,f++;
while(M%2==0)M/=2,t++;
if(M!=1){
cout<<-1<<endl;
return;
}
while(n%10==0)n/=10;
n%=10;
if(f<t){
for(int i = 0;i<t-f;i++){
n*=5;
n%=10;
}
}else{
for(int i = 0;i<f-t;i++){
n*=2;
n%=10;
}
}
cout<<n<<endl;
}
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> m;
solve();
}