結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー zhanghonghe2
提出日時 2021-07-22 00:44:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 991 ms / 2,000 ms
コード長 1,502 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 80,900 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-03 02:46:52
合計ジャッジ時間 11,993 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#define ll long long
using namespace std;

const int maxn=1000;
ll vis[maxn];
vector<ll> prime;

void init(){
    for(int i=2;i<maxn;i++){
        if(vis[i]==0) {
            prime.push_back(i);
            for(int j=i;j<maxn;j+=i){
                vis[j]=i;
            }
        }
    }
}

set<ll> s;

bool check(ll i,ll x){
    //if(x%i==0) return false;
    ll i2=i;
    s.clear();
    while(i2!=1){
        s.insert(vis[i2]);
        i2/=vis[i2];
    }
    vector<int> cnt1(s.size());
    vector<int> cnt2(s.size());

    int now=0;
    for(ll j:s){
        while(i%j==0) {
            i/=j;
            cnt1[now]+=1;
        }
        while(x%j==0){
            x/=j;
            cnt2[now]+=1;
        }
        now+=1;
    }

    int sum1=1;int sum2=1;
    for(int j:cnt2) sum1*=(j+1);
    for(int j=0;j<cnt2.size();j++){
        cnt2[j]+=cnt1[j];
        sum2*=(cnt2[j]+1);
    }

    return sum2==2*sum1;
}

int main(){
    ios::sync_with_stdio(false);
    int T;cin>>T;
    init();

    while(T--){
        ll X;cin>>X;

        ll p=-1;
        for(ll i:prime){
            if(X%i!=0){
                p=i;
                break;
            }
        }
        ll ans=p*X;

        for(ll i=p-1;i>=2;i--){
            //i 是一个合数,i可以被X的因子表示,但是i不能被X整除。
            if(check(i,X)){
                ans=i*X;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
0