結果

問題 No.368 LCM of K-products
ユーザー mkikenmkiken
提出日時 2016-04-30 04:05:13
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,480 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 93,012 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 08:02:56
合計ジャッジ時間 3,627 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
6,816 KB
testcase_01 AC 110 ms
6,944 KB
testcase_02 AC 111 ms
6,944 KB
testcase_03 AC 111 ms
6,944 KB
testcase_04 AC 111 ms
6,944 KB
testcase_05 AC 109 ms
6,944 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 60 ms
6,944 KB
testcase_14 AC 90 ms
6,940 KB
testcase_15 AC 100 ms
6,940 KB
testcase_16 AC 87 ms
6,944 KB
testcase_17 AC 75 ms
6,944 KB
testcase_18 AC 103 ms
6,940 KB
testcase_19 AC 30 ms
6,940 KB
testcase_20 AC 69 ms
6,940 KB
testcase_21 AC 21 ms
6,940 KB
testcase_22 AC 99 ms
6,944 KB
testcase_23 AC 5 ms
6,940 KB
testcase_24 AC 5 ms
6,944 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 AC 6 ms
6,940 KB
testcase_28 AC 5 ms
6,944 KB
testcase_29 AC 5 ms
6,940 KB
testcase_30 AC 6 ms
6,940 KB
testcase_31 AC 6 ms
6,940 KB
testcase_32 AC 6 ms
6,940 KB
testcase_33 WA -
testcase_34 AC 111 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void doIt()’:
main.cpp:140:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  140 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:143:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  143 |     scanf("%d", &a);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
//#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
//#include <limits>
#include <sstream>
//#include <functional>
using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = (s);i < (e);i++)
#define Rep(i, e) for(int i = 0;i < (e);i++)
#define rrep(i, e, s) for(int i = (e);(s) <= i;i--)
#define Rrep(i, e) for(int i = e;0 <= i;i--)
#define mrep(i, e, t1, t2) for(map<t1, t2>::iterator i = e.begin(); i != e.end(); i++)
#define setrep(i, e, t) for(set<t>::iterator i = e.begin(); i != e.end(); i++)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)(a), (t *)((a) + len(a)), v)
#define fmax(a, b) ((a) < (b)? (b) : (a))
#define fmin(a, b) ((a) > (b)? (b) : (a))
#define fabs(a) ((a) < 0? -(a) : (a))
#define pb push_back
#define fst(e) (e).first
#define snd(e) (e).second
#define rg(e, s, t) (s <= e && e < t)
#define PQDecl(name, tp) priority_queue< tp, vector<tp>, greater<tp> > name
#define dq(q) q.top();q.pop();
#define sz(v) ((int)(v).size())
#define lg(s) ((int)(s).length())
//#define X real()
//#define Y imag()
//typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<int> VI;
//typedef complex<double> p;
const int INF = (int)2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const ll weight[] = {1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13};

void prtAI(int *a, int n){
  Rep(i, n) printf("%d%c", a[i], i==n-1?'\n':' ');
}
void prtVI(const VI &v){
  Rep(i, sz(v)) printf("%d%c", v[i], i==sz(v)-1?'\n':' ');
}
void prtP(P p){
  printf("%d, %d\n", p.first, p.second);
}
void prtVP(const vector<P> &vp){
  Rep(i, sz(vp)) prtP(vp[i]);
}

#define MAX_N 100002
#define MAX_PRIMES 100002
bool bPrimes[MAX_PRIMES+5];
vector<int> primes;
int max_primes;

void initialize_prime_data(int max_prime){
  if (max_prime > MAX_PRIMES){
    printf("too large max_prime // %d\n", max_prime);
    exit(1);
  }
  afill(bPrimes, true);
  primes.clear();
  bPrimes[0] = bPrimes[1] = false;
  max_primes = max_prime;
}

void makePrimes(int max_prime){
  initialize_prime_data(max_prime);
  rep(i, 2, max_prime+5){
    if(bPrimes[i]){
      primes.push_back(i);
      for(int j = 2*i; j < max_prime+5; j += i) bPrimes[j] = false;
    }
  }
}


/**
 * @brief 素因数分解を行う
 * @param number 素因数分解する数
 * @return (素数、指数)を要素とするvector<P>
 */
vector<P> prime_factorize(ll number){
  if (primes.size() == 0){
    printf("not initialize primes\n");
    exit(1);
  }
  else if ((ll)max_primes * (ll)max_primes < number){
    printf("max_primes too small. // max_primes = %d, number = %lld\n", max_primes, number);
    exit(1);
  }
  vector<P> result;
  Rep(i, primes.size()){
    int div = 0;
    while(number % primes[i] == 0){
      div++;
      number /= primes[i];
    }
    if (div){
      result.push_back(P(primes[i], div));
    }
  }
  if (number > 1){
    result.push_back(P(number, 1));
  }
  return result;
}

void doIt(){
  int n, k;
  vector<int> v[MAX_N];
  map<int, int> s;
  int a;
  vector<P> tmp;

  makePrimes(MAX_N);

  scanf("%d%d", &n, &k);

  Rep(i, n){
    scanf("%d", &a);
    tmp = prime_factorize(a);
    Rep(j, tmp.size()){
      if (tmp[j].first >= MAX_N){
        s[tmp[j].first]++;
      }
      else{
        v[tmp[j].first].pb(tmp[j].second);
      }
    }

  }

  ull ans = 1;
  // 小さい数
  Rep(i, MAX_N){
    vector<int> tv = v[i];
    int exp = 0;
    if (tv.empty()){
      continue;
    }
    // cout << "----------" << endl;
    // cout << i << endl;
    // prtVI(tv);
    // cout << "----------" << endl;
    vrsort(tv);
    // prtVI(tv);
    Rep(j, min(k, sz(tv))){
      exp += tv[j];
    }

    Rep(j, exp){
      ans = ans * i % MOD;
    }
  }

  // 大きい数
  mrep(i, s, int, int){
    Rep(j, (*i).second){
      ans = ans * (*i).first % MOD;
    }
  }
  cout << ans << endl;
}

int main() {
  doIt();
  return 0;
}
0