結果

問題 No.1339 循環小数
ユーザー shu8Creamshu8Cream
提出日時 2021-01-16 09:36:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,231 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 198,704 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-18 06:04:08
合計ジャッジ時間 6,047 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
*    author:  shu8Cream
*    created: 15.01.2021 23:09:42
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int junkan(int n)
{
    int m=1; // 剰余を保持する変数(初期値1)
    int s=0; // 循環節の開始位置
    int t=0; // 循環節の終了位置
    int*list=(int*)calloc(n-1,sizeof(int)); // リストの初期化
    while (true)
    {
        // mが剰余リストにある場合はループ終了
        for(s=0;list[s];s++)
            if(m==list[s])
                goto END;
        // 剰余リストになかった場合は、終端に追加
        list[s]=m;
        // 次の剰余を計算
        m=(m*10)%n;
        // 割り切れる場合はループ終了
        if(m==0)goto END;
        t++;
    }
END:
    free(list); // リストの解放
    if(t-s==0) return 1;
    else return t-s; // 結果を出力
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--){
        int n; cin >>n;
        int a = junkan(n);
      	cout << a << endl;
    }
}
0