結果

問題 No.25 有限小数
ユーザー momoyuumomoyuu
提出日時 2022-08-16 14:03:49
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 3,230 ms
コンパイル使用メモリ 246,640 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-03 05:14:57
合計ジャッジ時間 4,281 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define rep(i,a,b) for (int i = a; i < b; i++)
#define irep(i,a,b) for (int i = a; i > b; i--)
#define print(n) cout << n << endl
#define rup(a,b) (a+b-1)/b

using namespace std;

unsigned ll gcd(unsigned ll a,unsigned ll b){
    if (a<b){
        swap(a,b);
    }
    if (b==0) return a;
    return gcd(b,a%b);
}

int main(){
    cout << fixed << setprecision(15);
    
    unsigned ll N,M;
    cin>>N>>M;

    unsigned ll d;

    bool p = false;

    d = gcd(N,M);
    N /= d;
    M /= d;
    unsigned ll now = 1;
    int count = 0;
    while(true){
        count ++ ;
        if (count>=100) break;
        d = gcd(M,10);
        //cout<<M<<d<<endl;
        if (d==1) break;
        M /= d;
        now *= (10/d);
    }
    if (M == 1){
        string s = to_string(N);
        char now = '1';
        rep(i,0,s.size()){
            if (s[i]=='0'){
                continue;
            }
            now = s[i];
        }
        print(now);
    }else{
        print(-1);
    }
    //system("pause");
    return 0;
}
0