結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー 蜜蜂蜜蜂
提出日時 2021-07-21 21:31:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,118 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 179,112 KB
実行使用メモリ 12,188 KB
最終ジャッジ日時 2023-09-24 15:29:17
合計ジャッジ時間 8,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘std::vector<long long int> divisor(ll)’ 内:
main.cpp:63:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   63 |     auto [a,b]=fac[i];
      |          ^
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:103:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  103 |     for(auto [value,cnt]:p){
      |              ^

ソースコード

diff #

//g++ CF3.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--)

//nを素因数分解 {素因数,個数} で管理 (1は空配列)
vector<pair<ll,ll>> factor(ll n){
  vector<pair<ll,ll>> res;

  int a=0;
  while(n%2==0){
    n/=2;
    a++;
  }

  if(a>0){
    res.pb({2,a});
  }

  for(ll x=3;x*x<=n;x+=2){
    if(n%x==0){
      a=0;
      while(n%x==0){
        n/=x;
        a++;
      }
      res.pb({x,a});
    }
  }

  if(n>1){
    res.pb({n,1});
  }

  return res;
}

//nの約数配列(昇順)
vector<ll> divisor(ll n){
  auto fac=move(factor(n));
  int sz=fac.size();
  
  vector<vector<ll>> x(sz);
  for(int i=0;i<sz;i++){
    auto [a,b]=fac[i];
    ll now=1;
    for(int j=0;j<=b;j++){
      x[i].pb(now);
      now*=a;
    }
  }
  
  vector<vector<ll>> res(sz);
  res[0]=x[0];
  
  for(int i=1;i<sz;i++){
    for(int j=0;j<res[i-1].size();j++){
      for(int k=0;k<x[i].size();k++){
        res[i].pb(res[i-1][j]*x[i][k]);
      }
    }
  }

  sort(all(res[sz-1]));
  
  return res[sz-1];
}

void solve(){
  ll n;
  cin>>n;

  if(n==1){
    cout<<"2\n";
    return;
  }

  auto x=divisor(n);
  auto p=factor(n);
  int z=x.size();

  rep(i,2,100){
    ll check=i*n;
    int check2=1;
    for(auto [value,cnt]:p){
      int check3=0;
      while(check%value==0){
        check/=value;
        check3++;
      }
      check2*=check3+1;
    }

    if(check>1){
      check2*=2;
    }

    if(check2==z*2){
      cout<<i*n<<"\n";
      return;
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  cin>>t;
  //t=1;
  while(t--){
    solve();
  }
}
0