結果

問題 No.25 有限小数
ユーザー A8pf
提出日時 2018-10-30 01:18:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,181 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 58,792 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-19 10:07:39
合計ジャッジ時間 1,482 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
using ll=long long;

ll gcd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

int main()
{
    ll n,m;
    ll ans=-1;
    cin>>n>>m;
    ll g=gcd(n,m);
    n/=g;m/=g;

    if(m==1)
    {
        while(n%10==0)
            n/=10;
        ans=n%10;
        if(ans<0)
            ans+=10;
    }else{
        ll cnt2=0;
        ll cnt5=0;
        while(m%2==0)
        {
            m/=2;
            cnt2++;
        }
        while(m%5==0)
        {
            m/=5;
            cnt5++;
        }
        if(m==1)
        {
            while(n%10==0)
                n/=10;
            n%=10;
            if(n<0)
                n+=10;
            for(ll i=0;i<cnt2;i++)
            {
                n*=5;
            }
            while(n%10==0)
                n/=10;
            n%=10;
            if(n<0)
                n+=10;
            for(ll i=0;i<cnt5;i++)
            {
                n*=2;
            }
            while(n%10==0)
                n/=10;
            ans=n%10;
            if(ans<0)
                ans+=10;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0