結果

問題 No.1339 循環小数
ユーザー SSRSSSRS
提出日時 2021-01-15 21:46:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 170,256 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-04 23:17:18
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge4 / 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 11 ms
5,376 KB
testcase_32 AC 11 ms
5,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 22 ms
5,376 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b, long long MOD){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
int gcd(int a, int b){
  if (b == 0){
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int lcm(int a, int b){
  return a / gcd(a, b) * b;
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N;
    cin >> N;
    while (N % 2 == 0){
      N /= 2;
    }
    while (N % 5 == 0){
      N /= 5;
    }
    vector<int> p;
    for (int j = 2; j * j <= N; j++){
      if (N % j == 0){
        p.push_back(j);
        while (N % j == 0){
          N /= j;
        }
      }
    }
    if (N > 1){
      p.push_back(N);
    }
    int ans = 1;
    for (int j : p){
      vector<int> f;
      for (int k = 1; k * k <= j - 1; k++){
        if ((j - 1) % k == 0){
          f.push_back(k);
          if (k * k < j - 1){
            f.push_back((j - 1) / k);
          }
        }
      }
      int tmp = j - 1;
      for (int k : f){
        if (modpow(10, k, j) == 1){
          tmp = min(tmp, k);
        }
      }
      ans = lcm(ans, tmp);
    }
    cout << ans << endl;
  }
}
0