結果

問題 No.747 循環小数N桁目 Hard
ユーザー xuzijian629xuzijian629
提出日時 2018-10-26 21:15:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 7,606 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 178,584 KB
実行使用メモリ 20,068 KB
最終ジャッジ日時 2024-04-29 22:06:23
合計ジャッジ時間 8,089 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
19,652 KB
testcase_01 AC 22 ms
19,660 KB
testcase_02 AC 25 ms
19,660 KB
testcase_03 AC 26 ms
19,784 KB
testcase_04 AC 25 ms
19,656 KB
testcase_05 AC 25 ms
19,656 KB
testcase_06 AC 26 ms
19,656 KB
testcase_07 AC 27 ms
19,660 KB
testcase_08 AC 26 ms
19,660 KB
testcase_09 AC 25 ms
19,656 KB
testcase_10 WA -
testcase_11 AC 23 ms
19,656 KB
testcase_12 AC 23 ms
19,652 KB
testcase_13 AC 24 ms
19,656 KB
testcase_14 AC 25 ms
19,660 KB
testcase_15 AC 24 ms
19,656 KB
testcase_16 AC 25 ms
19,660 KB
testcase_17 AC 24 ms
19,656 KB
testcase_18 AC 24 ms
19,656 KB
testcase_19 AC 26 ms
19,656 KB
testcase_20 AC 25 ms
19,656 KB
testcase_21 AC 25 ms
19,656 KB
testcase_22 AC 26 ms
19,656 KB
testcase_23 AC 25 ms
19,656 KB
testcase_24 WA -
testcase_25 AC 24 ms
19,660 KB
testcase_26 WA -
testcase_27 AC 26 ms
19,660 KB
testcase_28 AC 25 ms
19,652 KB
testcase_29 AC 25 ms
19,656 KB
testcase_30 AC 24 ms
19,780 KB
testcase_31 AC 25 ms
19,656 KB
testcase_32 AC 26 ms
19,656 KB
testcase_33 AC 26 ms
19,796 KB
testcase_34 AC 25 ms
19,700 KB
testcase_35 AC 24 ms
19,716 KB
testcase_36 AC 24 ms
19,760 KB
testcase_37 AC 24 ms
19,680 KB
testcase_38 AC 26 ms
19,868 KB
testcase_39 AC 27 ms
19,728 KB
testcase_40 WA -
testcase_41 AC 28 ms
19,812 KB
testcase_42 AC 26 ms
19,764 KB
testcase_43 AC 26 ms
19,608 KB
testcase_44 AC 27 ms
19,756 KB
testcase_45 AC 26 ms
19,792 KB
testcase_46 AC 26 ms
19,756 KB
testcase_47 AC 27 ms
19,796 KB
testcase_48 AC 25 ms
19,764 KB
testcase_49 AC 25 ms
19,756 KB
testcase_50 AC 25 ms
19,756 KB
testcase_51 AC 25 ms
19,876 KB
testcase_52 AC 26 ms
19,708 KB
testcase_53 AC 29 ms
19,932 KB
testcase_54 WA -
testcase_55 AC 30 ms
19,920 KB
testcase_56 AC 28 ms
19,888 KB
testcase_57 AC 26 ms
19,712 KB
testcase_58 AC 30 ms
19,944 KB
testcase_59 AC 25 ms
19,748 KB
testcase_60 AC 28 ms
19,900 KB
testcase_61 AC 27 ms
19,852 KB
testcase_62 AC 27 ms
19,876 KB
testcase_63 AC 28 ms
19,796 KB
testcase_64 AC 28 ms
19,884 KB
testcase_65 AC 26 ms
19,680 KB
testcase_66 AC 27 ms
19,752 KB
testcase_67 AC 26 ms
19,892 KB
testcase_68 AC 28 ms
19,792 KB
testcase_69 AC 28 ms
19,764 KB
testcase_70 WA -
testcase_71 AC 26 ms
19,704 KB
testcase_72 AC 25 ms
19,888 KB
testcase_73 AC 28 ms
19,792 KB
testcase_74 AC 28 ms
19,764 KB
testcase_75 AC 27 ms
19,716 KB
testcase_76 AC 27 ms
19,740 KB
testcase_77 AC 26 ms
19,740 KB
testcase_78 AC 28 ms
19,792 KB
testcase_79 AC 28 ms
19,768 KB
testcase_80 AC 27 ms
19,916 KB
testcase_81 AC 25 ms
19,704 KB
testcase_82 AC 27 ms
19,760 KB
testcase_83 AC 27 ms
19,708 KB
testcase_84 AC 28 ms
19,812 KB
testcase_85 AC 28 ms
19,808 KB
testcase_86 AC 28 ms
19,908 KB
testcase_87 AC 28 ms
19,932 KB
testcase_88 AC 28 ms
19,744 KB
testcase_89 AC 26 ms
19,768 KB
testcase_90 AC 27 ms
19,768 KB
testcase_91 AC 28 ms
19,788 KB
testcase_92 AC 28 ms
19,760 KB
testcase_93 AC 27 ms
19,772 KB
testcase_94 AC 28 ms
19,880 KB
testcase_95 AC 28 ms
19,900 KB
testcase_96 AC 28 ms
19,888 KB
testcase_97 AC 28 ms
19,864 KB
testcase_98 WA -
testcase_99 AC 28 ms
19,984 KB
testcase_100 AC 29 ms
20,036 KB
testcase_101 AC 29 ms
19,848 KB
testcase_102 AC 28 ms
19,768 KB
testcase_103 AC 28 ms
19,824 KB
testcase_104 AC 27 ms
19,828 KB
testcase_105 AC 28 ms
19,828 KB
testcase_106 AC 28 ms
19,828 KB
testcase_107 AC 32 ms
19,832 KB
testcase_108 AC 28 ms
19,824 KB
testcase_109 AC 29 ms
19,956 KB
testcase_110 AC 28 ms
19,824 KB
testcase_111 AC 29 ms
19,824 KB
testcase_112 AC 28 ms
19,832 KB
testcase_113 AC 28 ms
19,828 KB
testcase_114 AC 29 ms
19,952 KB
testcase_115 AC 28 ms
19,832 KB
testcase_116 AC 30 ms
19,832 KB
testcase_117 AC 27 ms
19,832 KB
testcase_118 WA -
testcase_119 AC 28 ms
19,828 KB
testcase_120 AC 29 ms
19,828 KB
testcase_121 AC 28 ms
19,824 KB
testcase_122 WA -
testcase_123 AC 28 ms
19,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;
constexpr i64 Z = i64(0);
using ii = pair<int, int>;

// 負の数は扱っていない
// 宣言するときはconvert関数を使う
// 掛け算でFFTをやるので畳み込み後の配列の最大要素を1e13程度にして誤差を小さくしたい
// BASELOGを大きくすると桁数が1/BASELOGになる代わりに配列の要素が指数関数的に大きくなる
// 掛け算をしないのであれば定数倍早くなるのでBASELOGを大きくするとよい。掛け算をするときは3が精度的に安心
constexpr i64 BASE = 1000;
constexpr int BASELOG = 3;
struct BigInt {
    // 掛け算のために本来の最大桁数の2倍必要
    vi digit = vi(1 << 18);
    int size;
    BigInt(int size = 1, i64 a = 0) : size(size) {
        digit[0] = a;
    }
    BigInt(const BigInt& a) {
        size = a.size;
        digit = vi(a.digit);
    }
};

bool operator<(BigInt x, BigInt y) {
    if (x.size != y.size) {
        return x.size < y.size;
    }
    for (int i = x.size - 1; i >= 0; i--) {
        if (x.digit[i] != y.digit[i]) {
            return x.digit[i] < y.digit[i];
        }
    }
    return false;
}

bool operator>(BigInt x, BigInt y) {
    return y < x;
}
bool operator<=(BigInt x, BigInt y) {
    return !(y < x);
}
bool operator>=(BigInt x, BigInt y) {
    return !(x < y);
}
bool operator!=(BigInt x, BigInt y) {
    return x < y || y < x;
}
bool operator==(BigInt x, BigInt y) {
    return !(x < y) && !(y < x);
}

BigInt normal(BigInt x, bool all = false) {
    i64 c = 0;
    if (all) {
        x.size = int(x.digit.size()) - 1;
    }
    for (int i = 0; i < x.size; i++) {
        while (x.digit[i] < 0) {
            x.digit[i + 1] -= 1;
            x.digit[i] += BASE;
        }
        while (x.digit[i] >= BASE) {
            x.digit[i + 1] += 1;
            x.digit[i] -= BASE;
        }
        i64 a = x.digit[i] + c;
        x.digit[i] = a % BASE;
        c = a / BASE;
    }
    for (; c > 0; c /= BASE) {
        x.digit[x.size++] = c % BASE;
    }
    while (x.size > 1 && x.digit[x.size - 1] == 0) {
        x.size--;
    }
    return x;
}

BigInt convert(i64 a) {
    return normal(BigInt(1, a), true);
}

BigInt convert(const string& s) {
    BigInt x;
    assert(s.size() / BASELOG <= x.digit.size() / 2);
    int i = s.size() % BASELOG;
    if (i > 0) {
        i -= BASELOG;
    }
    for (; i < int(s.size()); i += BASELOG) {
        i64 a = 0;
        for (int j = 0; j < BASELOG; j++) {
            a = 10 * a + (i + j >= 0 ? s[i + j] - '0' : 0);
        }
        x.digit[x.size++] = a;
    }
    reverse(x.digit.begin(), x.digit.begin() + x.size);
    return normal(x);
}

ostream &operator<<(ostream& os, BigInt x) {
    os << x.digit[x.size - 1];
    for (int i = x.size - 2; i >= 0; i--) {
        os << setw(BASELOG) << setfill('0') << x.digit[i];
    }
    return os;
}

istream &operator>>(istream& is, BigInt &x) {
    string s;
    is >> s;
    x = convert(s);
    return is;
}

string to_string(BigInt &x) {
    stringstream ss;
    ss << x.digit[x.size - 1];
    for (int i = x.size - 2; i >= 0; i--) {
        ss << setw(BASELOG) << setfill('0') << x.digit[i];
    }
    return ss.str();
}

BigInt operator+(BigInt x, BigInt y) {
    if (x.size < y.size) {
        x.size = y.size;
    }
    for (int i = 0; i < y.size; i++) {
        x.digit[i] += y.digit[i];
    }
    return normal(x);
}

BigInt operator-(BigInt x, BigInt y) {
    assert(x >= y);
    for (int i = 0; i < y.size; i++) {
        x.digit[i] -= y.digit[i];
    }
    return normal(x);
}

BigInt operator*(BigInt x, i64 a) {
    for (int i = 0; i < x.size; i++) {
        x.digit[i] *= a;
    }
    return normal(x);
}

void fft(vector<complex<double>>& a, bool inv = false) {
    int n = int(a.size());
    if (n == 1) return;
    vector<complex<double>> even(n / 2), odd(n / 2);
    for (int i = 0; i < n / 2; i++) {
        even[i] = a[2 * i];
        odd[i] = a[2 * i + 1];
    }
    fft(even, inv);
    fft(odd, inv);
    complex<double> omega = polar(1.0, (-2 * inv + 1) * 2 * acos(-1) / n);
    complex<double> pow_omega = 1.0;
    for (int i = 0; i < n / 2; i++) {
        a[i] = even[i] + pow_omega * odd[i];
        a[i + n / 2] = even[i] - pow_omega * odd[i];
        pow_omega *= omega;
    }
}

void conv(vector<complex<double>>& a, vector<complex<double>>& b) {
    fft(a);
    fft(b);
    int n = int(a.size());
    for (int i = 0; i < n; i++) {
        a[i] *= b[i] / complex<double>(n);
    }
    fft(a, true);
}

void conv(vi& a, vi& b) {
    vector<complex<double>> ac, bc;
    for (int i = 0; i < a.size(); i++) {
        ac.push_back(a[i]);
        bc.push_back(b[i]);
    }
    conv(ac, bc);
    a.resize(ac.size());
    for (int i = 0; i < ac.size(); i++) {
        a[i] = long(real(ac[i]) + 0.5);
    }
}

BigInt operator*(BigInt x, BigInt y) {
    conv(x.digit, y.digit);
    return normal(x, true);
}

pair<BigInt, i64> divmod(BigInt x, i64 a) {
    i64 c = 0, t;
    for (int i = x.size - 1; i >= 0; i--) {
        t = BASE * c + x.digit[i];
        x.digit[i] = t / a;
        c = t % a;
    }
    return pair<BigInt, i64>(normal(x), c);
}

BigInt operator/(BigInt x, i64 a) {
    return divmod(x, a).first;
}

i64 operator%(BigInt x, i64 a) {
    return divmod(x, a).second;
}

int main() {
    string n, k;
    cin >> n >> k;
    BigInt N = convert(n), K = convert(k);
    int a = N % 6;
    int b = K % 2;
    string hoge = "285714";
    if (a == 0) {
        cout << hoge[5] << endl;
        return 0;
    } else if (a == 1) {
        cout << 2 << endl;
        return 0;
    } else if (a == 2) {
        cout << (b == 0 ? hoge[3] : hoge[1]) << endl;
        return 0;
    } else if (a == 3) {
        cout << hoge[2] << endl;
        return 0;
    } else if (a == 4) {
        cout << hoge[3] << endl;
        return 0;
    } else {
        cout << (b == 0 ? hoge[5] : hoge[0]) << endl;
        return 0;
    }
}










































0