結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー chocoruskchocorusk
提出日時 2020-10-09 22:07:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,756 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 130,496 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 14:41:42
合計ジャッジ時間 1,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 53 ms
4,380 KB
testcase_15 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
ll powmod(ll a, ll k, ll MOD){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
vector<P> fac(ll n){
    vector<P> f;
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
            int e=0;
            while(n%i==0){
                n/=i;
                e++;
            }
            f.push_back({i, e});
        }
    }
    if(n>1) f.push_back({n, 1});
    return f;
}
ll solve(ll n){
  if(n==1){
    return 1;
  }
    ll x=2*n-1;
    auto f1=fac(x);
    ll phi=x;
    for(auto q:f1){
        phi/=q.first;
        phi*=(q.first-1);
    }
    auto f=fac(phi);
    ll res=phi;
    for(auto q:f){
        int e=q.second;
        ll p=q.first;
        ll pp=p;
        bool myon=0;
        for(int i=1; i<=e; i++){
            if(powmod(2, res/pp, x)!=1){
                res/=pp;
                res*=p;
                myon=1;
                break;
            }
            pp*=p;
        }
        if(!myon){
            res/=(pp/p);
        }
    }
    return res;
}
int main()
{
    int t; cin>>t;
    while(t--){
        ll n; cin>>n;
        cout<<solve(n)<<endl;
    }
    return 0;
}
0