結果

問題 No.1842 Decimal Point
ユーザー milanis48663220milanis48663220
提出日時 2022-02-18 23:21:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 3,063 bytes
コンパイル時間 1,150 ms
コンパイル使用メモリ 119,396 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 20:08:25
合計ジャッジ時間 2,729 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 179 ms
4,380 KB
testcase_02 AC 257 ms
4,380 KB
testcase_03 AC 252 ms
4,376 KB
testcase_04 AC 218 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef __int128_t ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

istream & operator >> (istream &in,  __int128_t &m){
    string s; cin >> s;
    m = parse(s);
    return in;
}


ostream &operator<<(std::ostream &dest, __int128_t value) {
    ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = end(buffer);
        do {
        --d;
        *d = "0123456789"[tmp % 10];
        tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
        --d;
        *d = '-';
        }
        int len = end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
        dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}


ll mod_pow(ll a, ll n, ll mod) {
    ll ans = 1;
    while (n > 0) {
        if (n&1) ans = (ans*a)%mod;
        a = (a*a)% mod;
        n >>= 1;
    }
    return ans;
}

void solve(){
    ll a, b, c; cin >> a >> b >> c;
    while(b%2 == 0){
        if(a%2 == 0){
            a /= 2;
        }else{
            a *= 5;
            c--;
        }
        b /= 2;
    }
    while(b%5 == 0){
        if(a%5 == 0){
            a /= 5;
        }else{
            a *= 2;
            c--;
        }
        b /= 5;
    }
    // cout << a << ' ' << b << ' ' << c << endl;
    if(c <= 0){
        ll x = a/b;
        while(c != 0) {
            x /= 10;
            c++;
        }
        cout << x%10 << endl;
        return;
    }
    ll x = (a*mod_pow(10, c, b))%b;
    int r = (10-x%10)%10;
    for(int i = 0; i < 10; i++){
        if((b*i)%10 == r){
            cout << i << endl;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
0