luogu的noip模拟赛T1,re了11个点,报错信息为Segmentation fault with invalid memory reference,但是我自己没有找出来。。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e4 + 5;
int n, m, num, max_val = 1, max_plc, x, p, cnt, len, flg;
bool fist_exist;
vector<int>find_factor[maxn];
vector<map<int, int> >factor;
queue<int>m_factor;
signed main(){
//freopen("plant.in", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
factor.resize(n + 5);
num = m;
for(int i = 2; i * i <= num; i++){//find prime_factors of m
while(num % i == 0){
num = num / i;
m_factor.push(i);
}
}
if(num != 1){
m_factor.push(num);
}
for(int i = 1; i <= n; i++){//find prime_factors and number of factors of p[i]s
cin >> p;
num = p;
for(int j = 2; j * j <= num; j++){
cnt = 0;
while(num % j == 0){
cnt++;
num = num / j;
}
if(cnt != 0){
factor[i][j] = cnt;//vector<map>
find_factor[i].push_back(j);
}
}
if(num != 1){
factor[i][num]++;
if(find_factor[i][find_factor[i].size() - 1] != num){
find_factor[i].push_back(num);
}
}
len = find_factor[i].size();
for(int j = 0; j < len; j++){
//cout << i << " " << find_factor[i][j] << " " << factor[i][find_factor[i][j]] << " ";
max_val *= (factor[i][find_factor[i][j]] + 1);
//cout << max_val << endl;
}
}
//cout << max_val << endl;
cnt = 0;//
while(!m_factor.empty()){
cnt++;
x = m_factor.front();
m_factor.pop();
max_plc = 1;
for(int i = 1; i <= n; i++){
if(factor[i][x]){
if(flg < (max_val / (factor[i][x] + 1)) * (factor[i][x] + 2)){
flg = (max_val / (factor[i][x] + 1)) * (factor[i][x] + 2);//
max_plc = i;
fist_exist = false;
}
}
else{
if(flg < max_val * 2){
flg = max_val * 2;//
fist_exist = true;
max_plc = i;
}
}
}
if(fist_exist){
max_val *= 2;
}
else{
max_val = (max_val / (factor[max_plc][x] + 1)) * (factor[max_plc][x] + 2);
}
factor[max_plc][x]++;
//cout << max_plc << " " << max_val << endl;
}
cout << max_val << endl;
return 0;
}