結果

問題 No.1611 Minimum Multiple with Double Divisors
ユーザー tnakao0123tnakao0123
提出日時 2021-07-23 01:41:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,076 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 96,436 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-24 22:32:51
合計ジャッジ時間 6,663 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
8,272 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1611.cc:  No.1611 Minimum Multiple with Double Divisors - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_P = 320000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,int> pli;
typedef vector<pli> vpli;

/* global variables */

bool primes[MAX_P + 1];

/* subroutines */

int gen_primes(int maxp, vi &pnums) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums.push_back(p);
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums.push_back(p);
  return (int)pnums.size();
}

bool prime_decomp(ll n, vi &pnums, vpli& pds) {
  pds.clear();

  int pn = pnums.size();
  for (int i = 0; i < pn; i++) {
    int pi = pnums[i];
    if ((ll)pi * pi > n) {
      if (n > 1) pds.push_back(pli(n, 1));
      return true;
    }

    if (n % pi == 0) {
      int fi = 0;
      while (n % pi == 0) n /= pi, fi++;
      pds.push_back(pli(pi, fi));
    }
  }
  return false;
}

ll powll(ll a, int n) {  // a^n % MOD
  ll pm = 1;
  while (n > 0) {
    if (n & 1) pm *= a;
    a *= a;
    n >>= 1;
  }
  return pm;
}

/* main */

int main() {
  vi pnums;
  int pn = gen_primes(MAX_P, pnums);

  int tn;
  scanf("%d", &tn);

  while (tn--) {
    ll x;
    scanf("%lld", &x);

    vpli pds;
    prime_decomp(x, pnums, pds);

    ll minz = LINF;
    for (int i = 0, j = 0; i < pn; i++) {
      int f = 1;
      if (j < pds.size() && pnums[i] == pds[j].first)
	f = pds[j++].second + 1;
      minz = min(minz, powll(pnums[i], f));
      if (f == 1) break;
    }

    printf("%lld\n", x * minz);
  }
  return 0;
}
0