結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー fastmathfastmath
提出日時 2020-10-09 23:10:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,350 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 206,936 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 14:44:13
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 43 ms
4,376 KB
testcase_09 AC 45 ms
4,376 KB
testcase_10 AC 44 ms
4,380 KB
testcase_11 AC 43 ms
4,380 KB
testcase_12 AC 43 ms
4,384 KB
testcase_13 AC 5 ms
4,384 KB
testcase_14 AC 97 ms
4,380 KB
testcase_15 AC 41 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘long long int fast_solve()’ 内:
main.cpp:57:1: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
   57 | }
      | ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

int solve(int n) {
    vector <int> a(2 * n);
    for (int i = 0; i < 2 * n; ++i)
        a[i] = i;

    auto was = a;

    auto f = [&] (vector <int> a) {
        vector <int> ans;
        for (int i = 0; i < n; ++i) {
            ans.app(a[i]);
            ans.app(a[i + n]);
        }   
        return ans;
    };  

    int ans = 0;
    while (1) {
        a = f(a);
        ans++;
        if (a == was) {
            return ans;
        }   
    }   
    assert(0);
}

int phi (int n) {
    int result = n;
    for (int i=2; i*i<=n; ++i)
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    if (n > 1)
        result -= result / n;
    return result;
}

int fast_solve() {

}   

int fp(int a, int p, int mod) {
    int ans = 1, cur = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) {
            ans = (ans * cur) % mod;
        }   
        cur = (cur * cur) % mod;
    }   
    return ans;
}    

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;

        if (n == 1) {
            cout << 1 << endl;
            continue;
        }   

        int mod = 2 * n - 1;
        int ph = phi(mod);
        vector <int> a;
        for (int d = 1; d * d <= ph; ++d) {
            if (ph % d == 0) {
                a.app(d);
                a.app(ph/d);
            }   
        }   
        sort(all(a));
        for (auto e : a) {
            if (fp(2, e, mod) == 1) {
                cout << e << endl;
                break;
            }   
        }   
    }

    exit(0);

    /*
    for (int n = 1; n <= 100; ++n) {
        //cout << n << ' ' << solve(n) << endl;
        cout << solve(n) << ' ';
    }   
    cout << endl;
    */


}
0