結果

問題 No.25 有限小数
ユーザー kagasankagasan
提出日時 2019-08-22 22:34:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,076 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 173,184 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2024-04-21 06:22:15
合計ジャッジ時間 8,504 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

map<ll, ll>prime_factor(ll N){
    map<ll, ll>ret;
    for(ll i = 2; i * i <= N; i++){
        while(N % i == 0){
            ret[i]++;
            N /= i;
        }
    }
    if(N != 1)ret[N] = 1;
    return ret;
}


int main(){

    ll N, M;
    cin >> N >> M;
    map<ll, ll>mp;
    for(ll i = 2; i * i <= M; i++){
        while(M % i == 0){
            mp[i]--;
            M /= i;
        }
    }
    if(M != 1)mp[M]--;
    for(ll i = 2; i * i <= N; i++){
        while(N % i == 0){
            mp[i]++;
            N /= i;
        }
    }
    if(N != 1)mp[N]++;
    while(mp[2] < 0 || mp[5] < 0){
        mp[2]++;
        mp[5]++;
    }
    ll ans = 1;
    for(auto it = mp.begin(); it != mp.end(); it++){
        if((*it).second < 0){
            cout << -1 << endl;
            return 0;
        }
        for(ll i = 0; i < (*it).second; i++){
            ans *= (*it).first;
            while(ans % 10 == 0)ans /= 10;
            ans %= 10;
        }
    }
    cout << ans << endl;

    return 0;
}
0