結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
monnu
|
| 提出日時 | 2021-07-14 02:04:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 865 bytes |
| コンパイル時間 | 1,854 ms |
| コンパイル使用メモリ | 166,880 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-02 23:02:57 |
| 合計ジャッジ時間 | 3,301 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000009
//#define MOD 998244353
#define INF 1000000000
//#define INF 1000000000000000000
ll gcd(ll A,ll B){
while(A%B!=0){
ll tmp=A%B;
A=B;
B=tmp;
}
return B;
}
int main(){
ll N,M;
cin>>N>>M;
ll g=gcd(N,M);
N/=g;
M/=g;
if(M==1){
while(N%10==0){
N/=10;
}
cout<<N%10<<endl;
return 0;
}
while(M%10==0){
M/=10;
}
int cnt2=0;
int cnt5=0;
while(M%2==0){
cnt2++;
M/=2;
}
while(M%5==0){
cnt5++;
M/=5;
}
if(M>1){
cout<<-1<<endl;
return 0;
}
if(cnt2>0){
cout<<5<<endl;
}else{
ll x=N%10;
for(int i=0;i<cnt5;i++){
x%=5;
x*=2;
}
cout<<x<<endl;
}
}
monnu