結果
問題 | No.1255 ハイレーツ・オブ・ボリビアン |
ユーザー |
![]() |
提出日時 | 2020-10-09 22:07:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,756 bytes |
コンパイル時間 | 1,070 ms |
コンパイル使用メモリ | 127,340 KB |
最終ジャッジ日時 | 2025-01-15 04:46:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
#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_popcountusing 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;}