結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2022-05-28 19:08:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,031 bytes |
コンパイル時間 | 2,312 ms |
コンパイル使用メモリ | 210,296 KB |
最終ジャッジ日時 | 2025-01-29 16:48:26 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #ifdef __LOCAL #include <debug> #else #define debug(...) void(0) #endif #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template<typename T> istream& operator>>(istream&is,vector<T>&v){ for(T&p:v)is>>p; return is; } template<typename T> ostream& operator<<(ostream&os,const vector<T>&v){ if(&os==&cerr)os<<"["; for(int i=0;i<v.size();i++){ os<<v[i]; if(i+1<v.size())os<<(&os==&cerr?",":" "); } if(&os==&cerr)os<<"]"; return os; } using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n,m;cin>>n>>m; ll g=gcd(n,m); n/=g;m/=g; int tw=0,fi=0; while(m%2==0){ m/=2; tw++; } while(m%5==0){ m/=5; fi++; } if(m!=1){ cout<<-1<<endl; return 0; } int mn=min(tw,fi); tw-=mn;fi-=mn; if(tw){ while(n%10==0)n/=10; while(tw--)(n*=5)%=10; } else{ while(n%10==0)n/=10; while(fi--)(n*=2)%=10; } cout<<n%10<<endl; }