結果

問題 No.1339 循環小数
ユーザー outline
提出日時 2021-01-16 00:43:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 134,868 KB
最終ジャッジ日時 2025-01-17 21:02:27
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
int64_t euler_phi(int64_t n){
int res = n;
for(int64_t i = 2; i * i <= n; ++i){
if(n % i == 0){
res -= res / i;
while(n % i == 0) n /= i;
}
}
if(n != 1) res -= res / n;
return res;
}
ll modpow(ll x, ll n, int m){
ll res = 1;
while(n > 0){
if(n & 1) (res *= x) %= m;
(x *= x) %= m;
n >>= 1;
}
return res;
}
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 = euler_phi(N);
vector<int> div;
for(int i = 1; i * i <= phi; ++i){
if(phi % i == 0){
div.emplace_back(i);
if(i * i != phi) div.emplace_back(phi / i);
}
}
sort(begin(div), end(div));
for(auto d : div){
if(modpow(10LL, d, N) == 1){
cout << d << '\n';
return;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0