結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2017-05-03 00:39:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 610 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 23,936 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 04:49:04 |
合計ジャッジ時間 | 1,197 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#include<cstdio> using ll=long long; using ull=unsigned long long; ull gcd(ull a, ull b) { ull c; while((c=a%b)) { a=b; b=c; } return b; } void com_div(ull& a, ull& b) { ull d=gcd(a, b); a/=d; b/=d; } int main(void) { ull n, m, t; int c2, c5; while(scanf("%llu%llu", &n, &m)==2) { com_div(n, m); t=m; for(c2=0;t%2==0;t/=2) c2++; for(c5=0;t%5==0;t/=5) c5++; if(t!=1) { printf("-1\n"); continue; } if(c2>c5) { printf("5\n"); continue; } for(;n%10==0;n/=10); n%=10; for(int i=c5-c2;i>0;i--) n=(n*2)%10; printf("%d\n", (int)n); } return 0; }