結果

問題 No.1339 循環小数
ユーザー ytqm3ytqm3
提出日時 2021-05-17 20:44:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,441 bytes
コンパイル時間 2,491 ms
コンパイル使用メモリ 203,232 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 08:48:04
合計ジャッジ時間 3,913 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 AC 27 ms
5,376 KB
testcase_32 AC 27 ms
5,376 KB
testcase_33 WA -
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 23 ms
5,376 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

vector<int> div_enum(int n)
{
  vector<int> res;
  for(int i=1;i*i<=n;++i)
  {
    if(n%i!=0)
    {
      continue;
    }
    res.push_back(i);
    if(i!=n/i)
    {
      res.push_back(n/i);
    }
  }
  sort(res.begin(),res.end());
  return res;
}

vector<pair<int,int>> prime_fact(int n)
{
  vector<pair<int,int>> res;
  for(int i=2;i*i<=n;++i)
  {
    if(n%i!=0)
    {
      continue;
    }
    int exp=0;
    while(n%i==0)
    {
      n/=i;
      exp+=1;
    }
    res.push_back({i,exp});
  }
  if(n!=1)
  {
    res.push_back({n,1});
  }
  return res;
}

int power(int a,int b)
{
  int res=1;
  for(int i=0;i<b;++i)
  {
    res*=a;
  }
  return res;
}

int euler_func(int n)
{
  auto vec=prime_fact(n);
  int res=1;
  for(size_t i=0;i<vec.size();++i)
  {
    res*=power(vec[i].first,vec[i].second)-power(vec[i].first,vec[i].second-1);
  }
  return res;
}

int64_t pow_mod(int64_t a,int64_t n,int64_t mod)
{
  int64_t res=1,now=a;
  while(n)
  {
    if(n&1)
    {
      res=res*now%mod;
    }
    now=now*now%mod;
    n>>=1;
  }
  return res;
}

void solve()
{
  int n;
  cin>>n;
  n/=gcd(n,10);
  int Max=euler_func(n);
  auto vec=div_enum(Max);
  for(size_t i=0;i<vec.size();++i)
  {
    if(pow_mod(10,vec[i],n)==1)
    {
      cout<<vec[i]<<endl;
      return;
    }
  }
  cout<<1<<endl;
  return;
}

int main()
{
  int T;
  cin>>T;
  for(int i=0;i<T;++i)
  {
    solve();
  }
  return 0;
}
0