結果

問題 No.25 有限小数
ユーザー ayame_pyayame_py
提出日時 2016-01-07 13:35:52
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,105 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 163,208 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-10-19 16:24:23
合計ジャッジ時間 7,773 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
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;

#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 (double(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;
    }
    
    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