結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2022-08-16 14:20:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,673 bytes |
コンパイル時間 | 2,839 ms |
コンパイル使用メモリ | 247,456 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-03 05:30:52 |
合計ジャッジ時間 | 3,197 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>#define ll long long#define ld long double#define rep(i,a,b) for (int i = a; i < b; i++)#define irep(i,a,b) for (int i = a; i > b; i--)#define print(n) cout << n << endl#define rup(a,b) (a+b-1)/b#define end endl;using namespace std;unsigned ll gcd(unsigned ll a,unsigned ll b){if (a<b){swap(a,b);}if (b==0) return a;return gcd(b,a%b);}unsigned ll calc(unsigned ll N){string s = to_string(N);char now1 = '1';rep(i,0,s.size()){if (s[i]=='0'){continue;}now1 = s[i];}return (unsigned ll)(now1-'0');}int main(){cout << fixed << setprecision(15);unsigned ll N,M;cin>>N>>M;unsigned ll d;bool p = false;d = gcd(N,M);N /= d;M /= d;unsigned ll now = 1;int count = 0;while(true){count ++ ;if (count>=100) break;d = gcd(M,10);if (d==1) break;M /= d;now *= (10/d);now = calc(now);//cout<<now<<" "<<M<<end;}if (M == 1){string s = to_string(N);char now1 = '1';rep(i,0,s.size()){if (s[i]=='0'){continue;}now1 = s[i];}N = now * (int)(now1-'0');//cout<<now<<" "<<N<<" "<<(int)(now1-'0')<<endl;s = to_string(N);now1 = '1';rep(i,0,s.size()){if (s[i]=='0'){continue;}now1 = s[i];}print(now1);}else{print(-1);}//system("pause");return 0;}