結果

問題 No.747 循環小数N桁目 Hard
ユーザー mamekin
提出日時 2018-10-21 16:12:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 1,369 ms
コンパイル使用メモリ 114,536 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-19 03:24:33
合計ジャッジ時間 4,049 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 120
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 6;
const int POWMOD[] = {1, 1, 2, 1, 1, 2};

int div(const string& s, int x)
{
    int n = s.size();
    int ans = 0;
    for(int i=0; i<n; ++i){
        ans *= 10;
        ans += s[i] - '0';
        ans %= x;
    }
    return ans;
}

int main()
{
    string a, b;
    cin >> a >> b;

    int n = div(a, MOD);
    int k = div(b, POWMOD[n]) + POWMOD[n];

    int x = 1;
    for(int i=0; i<k; ++i){
        x *= n;
        x %= MOD;
    }
    cout << "428571"[x] << endl;

    return 0;
}
0