結果

問題 No.1339 循環小数
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2021-01-16 01:24:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,673 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 123,540 KB
実行使用メモリ 5,272 KB
最終ジャッジ日時 2023-08-17 20:13:57
合計ジャッジ時間 3,583 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 66 ms
4,380 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--)  // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++)  // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
    out << '[';
    for (int i=0;i<int(v.size());i++) {
        if (i) out << ", ";
        out << v[i];
    }
    return out << ']';
}

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll powmod(ll a, ll p, ll m) {
    if (p == 0) return 1;
    ll tmp = powmod(a, p >> 1, m);
    if (p & 1) return (tmp * tmp % m) * a % m;
    else return tmp * tmp % m;
}

void solve() {
    ll n; cin >> n;
    ll orign = n;
    while (orign % 2 == 0) orign /= 2;
    while (orign % 5 == 0) orign /= 5;
    if (orign == 1) {
        cout << 1 << '\n';
        return;
    }
    
    ll phi = orign - 1;
    for (ll i = 2; i * i <= orign; i++) {
        if (orign % i == 0) {
            phi -= (orign / i == i ? 1 : 2);
        }
    }

    int ans = INF;
    for (ll i = 1; i * i <= phi; i++) {
        if (phi % i == 0) {
            if (powmod(10, i, orign) == 1) chmin(ans, int(i));
            if (powmod(10, phi / i, orign) == 1) chmin(ans, int(phi / i));
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t-->0) {
        solve();
    }
    return 0;
}
0