結果

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

ソースコード

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

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;
#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<
template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
inline bool chmax(T &_l, const T b) {
if (_l < b) {
_l = b;
return true;
}
return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
if (_l > b) {
_l = b;
return true;
}
return false;
}
# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
if (i == bb.size() - 1) std::cout << bb[i];
else std::cout << bb[i] << ' ';
}
std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
for (unsigned int i = 0;i < bb.size();i++) {
std::cout << i << ' ';
vdeb(bb[i]);
}
std::cout << '\n';
}
# endif
using namespace std;
ll modpow(ll x, ll k, ll p) {
ll ret = 1;
while(k) {
if(k&1) ret = ret*x%p;
x = x*x%p;
k >>= 1;
}
return ret;
}
ll solve() {
ll n; cin >> n;
while(n%2 == 0) n /= 2;
while(n%5 == 0) n /= 5;
if(n == 0) return 1;
ll ans = n;
auto m = n;
rip(i, 100000, 2) {
if(n%i == 0) {
while(n%i == 0) n /= i;
ans /= i;
ans *= i-1;
}
}
if(n != 1) ans = ans/n*(n-1);
ll ret = ans;
rip(i, 100000, 1) {
if(ans%i == 0) {
if(modpow(10, i, m) == 1) chmin(ret, (ll)i);
if(modpow(10, ans/i, m) == 1) chmin(ret, ans/i);
}
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t; cin >> t;
rip(i,t,0) cout << solve() << endl;;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0