結果
問題 | No.25 有限小数 |
ユーザー |
![]() |
提出日時 | 2022-01-11 03:15:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 602 bytes |
コンパイル時間 | 2,060 ms |
コンパイル使用メモリ | 193,700 KB |
最終ジャッジ日時 | 2025-01-27 10:23:11 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%lld %lld",&n,&m); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; long long gcd(long long x,long long y){ long long r; while(x){ r=y; y=x; x=r%x; } return y; } int main(){ int i, j, k; int p2 = 0, p5 = 0; long long n,m,g; scanf("%lld %lld",&n,&m); g=gcd(n,m); n/=g; m/=g; while(m%2==0) m/=2,p2++; while(m%5==0) m/=5,p5++; if(m>1){ printf("-1"); return 0; } while(n%10==0) n/=10; n%=10; while(p2>p5) p5++,n=(n*5)%10; while(p2<p5) p2++,n=(n*2)%10; printf("%d\n",(int)n); return 0; }