結果

問題 No.1339 循環小数
ユーザー oteraotera
提出日時 2021-01-16 05:27:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,741 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 200,064 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 01:55:26
合計ジャッジ時間 4,345 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *    author:  otera    
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
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; }

ll modpow(ll a, ll n, ll m) {
    if(n == 0) return 1LL;
    ll ret = modpow(a * a % m, n / 2, m);
    if(n & 1) ret *= a;
    return ret % m;
}

void solve() {
    int n; cin >> n;
    while(n % 2 == 0) n /= 2;
    while(n % 5 == 0) n /= 5;
    if(n == 1) {
        cout << 1 << "\n";
        return;
    }
    int phi = 1;
    int n_ = n;
    for(int i = 2; i * i <= n_; ++ i) {
        if(n_ % i == 0) {
            int co = 0;
            while(n_ % i == 0) {
                ++ co;
                n_ /= i;
            }
            rep(j, co - 1) phi *= i;
            phi *= (i - 1);
        }
    }
    if(n_ != 1) phi *= (n_ - 1);
    int ans = phi;
    for(int k = 1; k * k <= phi; ++ k) {
        if(phi % k == 0) {
            if(modpow(10, k, n) == 1) {
                chmin(ans, k);
            }
            if(modpow(10, phi / k, n) == 1) {
                chmin(ans, phi / k);
            }
        }
    }
    cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	int t; cin >> t; rep(i, t)solve();
	// solve();
    return 0;
}
0