結果

問題 No.25 有限小数
ユーザー ayame_pyayame_py
提出日時 2016-01-07 13:39:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,142 bytes
コンパイル時間 1,311 ms
コンパイル使用メモリ 147,264 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 22:57:41
合計ジャッジ時間 2,678 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i < (ll)(m); i++)
#define INF 1000000007

typedef long long ll;

ll N, M;
map<ll,ll> prime;
map<ll,ll> prime2;

// 最大公約数 a < b;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}


int main(){
    
    cin >> N;
    cin >> M;
    
    ll g = gcd(N,M);

    N/=g;
    M/=g;
    
    // 整数の時
    if (N%M==0){
        ll t = N/M;
        while(true){
            if(t%10!=0){
                cout << t%10 << endl;
                return 0;
            }else{
                t/=10;
            }
        }
    }
    
    while(N%10==0) N/=10;
    N%=10;
    while(M%10==0) M/=10;
    
    // 2で割れる数
    ll M25[2]={0,0};
    while(M%2==0) {
        M25[0]++;
        M/=2;
    }
    
    // 5で割れる数
    while(M%5==0){
        M25[1]++;
        M/=5;
    }
    
    if(M!=1){cout << -1 << endl; return 0;}
    
    int t = 1;
    if(M25[0]>M25[1]) t = 5;
    else t = 2;
    REP(i,max(M25[0],M25[1])) N=(N*t)%10;
    
    cout << N << endl;
    
    return 0;
}
0