結果

問題 No.1339 循環小数
ユーザー zlnzln
提出日時 2021-01-15 22:00:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,568 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 103,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 17:05:37
合計ジャッジ時間 2,963 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

lnt ipow(lnt v,lnt k,lnt m) { lnt r(1),t(v); while(k){ if(k&1) {r*=t;r%=m;} t*=t; t%=m; k>>=1; } return r%m; }


int64_t euler_phi(int64_t n) {
  int64_t ret = n;
  for(int64_t i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) ret -= ret / n;
  return ret;
}

int main() {
	int t;
	std::cin >> t;
	rep(tt,t) {
		lnt n;
		std::cin >> n;
		if(10%n==0) {
			print(1);
			continue;
		}
		while(n%2==0) n/=2;
		while(n%5==0) n/=5;
		if(n==1) {
			print(1);
			continue;
		}
		lnt phi = euler_phi(n);
		lnt min = phi;
		for(lnt i=1;i*i<=phi;i++) {
			if(phi%i) continue;
			if(ipow(10,i,n)==1) min=std::min(min,i);
			if(ipow(10,phi/i,n)==1) min=std::min(min,phi/i);
		}
		print(min);
	}
}
0