結果
問題 | No.1611 Minimum Multiple with Double Divisors |
ユーザー | 蜜蜂 |
提出日時 | 2021-07-22 11:46:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,113 ms / 2,000 ms |
コード長 | 4,087 bytes |
コンパイル時間 | 2,074 ms |
コンパイル使用メモリ | 180,324 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-03 02:51:24 |
合計ジャッジ時間 | 15,449 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 464 ms
5,248 KB |
testcase_01 | AC | 258 ms
5,248 KB |
testcase_02 | AC | 276 ms
5,248 KB |
testcase_03 | AC | 278 ms
5,248 KB |
testcase_04 | AC | 280 ms
5,248 KB |
testcase_05 | AC | 273 ms
5,248 KB |
testcase_06 | AC | 286 ms
5,248 KB |
testcase_07 | AC | 274 ms
5,248 KB |
testcase_08 | AC | 272 ms
5,248 KB |
testcase_09 | AC | 273 ms
5,248 KB |
testcase_10 | AC | 180 ms
5,248 KB |
testcase_11 | AC | 1,113 ms
5,248 KB |
testcase_12 | AC | 934 ms
5,248 KB |
testcase_13 | AC | 942 ms
5,248 KB |
testcase_14 | AC | 976 ms
5,248 KB |
testcase_15 | AC | 930 ms
5,248 KB |
testcase_16 | AC | 935 ms
5,248 KB |
testcase_17 | AC | 924 ms
5,248 KB |
testcase_18 | AC | 921 ms
5,248 KB |
testcase_19 | AC | 6 ms
5,248 KB |
testcase_20 | AC | 6 ms
5,248 KB |
testcase_21 | AC | 6 ms
5,248 KB |
testcase_22 | AC | 6 ms
5,248 KB |
testcase_23 | AC | 6 ms
5,248 KB |
testcase_24 | AC | 6 ms
5,248 KB |
testcase_25 | AC | 6 ms
5,248 KB |
testcase_26 | AC | 5 ms
5,248 KB |
testcase_27 | AC | 6 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 2 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:196:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 196 | for(auto [value,cnt]:init){ | ^ main.cpp:206:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 206 | for(auto [value,cnt]:check){ | ^ main.cpp:219:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 219 | for(auto [value,cnt]:check){ | ^
ソースコード
//g++ 1.cpp -std=c++14 -O2 -I . #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; using vvld = vector<vld>; #define fi first #define se second #define pb push_back #define pq_big(T) priority_queue<T,vector<T>,less<T>> #define pq_small(T) priority_queue<T,vector<T>,greater<T>> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #include <cassert> #include <cmath> #include <initializer_list> #include <random> #include <iostream> #include <algorithm> std::mt19937_64 mt{std::random_device{}()}; long long rnd(long long n) { return std::uniform_int_distribution<long long>(0, n-1)(mt); } bool is_prime(long long x){ using u128=__uint128_t; if(x==2||x==3||x==5||x==7)return true; if(x%2==0||x%3==0||x%5==0||x%7==0)return false; if(x<121){ return x>1; } long long d = (x-1) >> __builtin_ctzll(x-1); long long one=1,minus_one=x-1; auto pow = [](long long x,long long n,long long mod){ u128 res; x%=mod; if(n==0){ res=1;return res; } res=1; u128 now=x; for(;n;n>>=1,now=(now*now)%mod){ if(n&1){ res=res*now%mod; } } return res; }; auto ok = [&](long long a){ auto y=pow(a,d,x); long long t=d; while(y!=one&&y!=minus_one&&t!=x-1){ y=y*y%x; t<<=1; } if(y!=minus_one&&t%2==0)return false; return true; }; if(x<(1ull<<32)){ for(long long a:{2,7,61}){ if(!ok(a))return false; } } else{ for(long long a:{2,325,9375,28178,450775,9780504,1795265022}){ if(x<=a)return true; if(!ok(a))return false; } } return true; } long long GCD(long long a,long long b){ if(b == 0){ return a; } else{ return GCD(b,(a%b)); } } long long rho(long long n,long long c){ using u128=__uint128_t; assert(n>1); long long cc=c; auto f = [&](long long x){ long long res; res=(((u128)x)*x+cc)%n; return res; }; long long x=1,y=2,z=1,q=1; long long g=1; long long m= 1LL<<((64-__builtin_ctzll(n))/5); for(long long r=1;g==1;r<<=1){ x=y; for(int i=0;i<r;i++){ y=f(y); } for(long long k=0;k<r&&g==1;k+=m){ z=y; for(long long i=0;i<std::min(m,r-k);i++){ y=f(y); long long w=(x-y)%n; if(w<0)w+=n; q=((u128)q*w)%n; } g=GCD(q,n); } } if(g==n){ do{ z=f(z); long long w=(x-z)%n; if(w<0)w+=n; g=GCD(w,n); }while(g==1); } return g; } long long prime_factor(long long n){ assert(n>1); if(is_prime(n)) return n; for(int i=0;i<100;i++){ long long m=rho(n,rnd(n)); if(is_prime(m))return m; n=m; } std::cerr<<"failed\n"; assert(false); return -1; } std::vector<std::pair<long long,int>> factor(long long n){ static std::vector<std::pair<long long,int>> res; res.clear(); for(long long i=2;i<=100&&i*i<=n;++i){ if(n%i==0){ int cnt=0; do{ cnt++; n/=i; }while(n%i==0); res.emplace_back(i,cnt); } } while(n>1){ long long p=prime_factor(n); int cnt=0; do{ cnt++; n/=p; }while(n%p==0); res.emplace_back(p,cnt); } std::sort(res.begin(),res.end()); return res; } void solve(){ ll x; cin>>x; vi count(50,0); auto init=move(factor(x)); int divisor=1; for(auto [value,cnt]:init){ if(value<50){ divisor*=(cnt+1); count[value]=cnt; } } rep(i,2,40){ auto check=move(factor(i)); int div=1; for(auto [value,cnt]:check){ count[value]+=cnt; } rep(j,0,50){ div*=(count[j]+1); } if(div==divisor*2){ cout<<i*x<<"\n"; return; } for(auto [value,cnt]:check){ count[value]-=cnt; } } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin>>t; while(t--){ solve(); } }