This commit is contained in:
Zengtudor 2024-11-14 12:00:24 +08:00
parent 1335cabe0a
commit 45b9ef50e3

View File

@ -1,125 +1,38 @@
// #include <array>
// #include <cstdint>
// #include <iostream>
// #include <ranges>
// #include <type_traits>
// #include <utility>
// using int64 = int64_t;
// template<class ...Args>
// void input(Args&&...args){
// (std::cin>>...>>std::forward<Args>(args));
// }
// template <class T>
// std::remove_cvref_t<T> input(){
// std::remove_cvref_t<T> t;
// std::cin>>t;
// return t;
// }
// template<class ...Args>
// void print(Args&&...args){
// (std::cout<<...<<std::forward<Args>(args));
// }
// const int64 max_n = 3e5 + 5;
// int main(){
// const int64 n = input<decltype(n)>(), m = input<decltype(m)>();
// const std::array<int64, max_n> s = [&]()->std::remove_cvref_t<decltype(s)>{
// std::remove_cvref_t<decltype(s)> ret;
// for(const auto &i : std::ranges::views::iota(1, n+1)){
// input(ret[i]);
// }
// return ret;
// }();
// }
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
const int MOD = 1e9 + 7;
const int MAX_VAL = 1e6;
using ll = int64_t;
#define nv(v)#v<<": "<<(v)<<' '
auto &ci = std::cin;
auto &co = std::cout;
// 最小素因子表,用于快速质因数分解
std::vector<int> spf(MAX_VAL + 1);
const ll mn = 1e6+5;
ll n;
ll *a = new ll[mn], *sa = new ll[mn];
// 初始化 SPF 表,使用埃拉托色尼筛法
void sieve() {
for (int i = 2; i <= MAX_VAL; ++i) {
if (spf[i] == 0) {
for (int j = i; j <= MAX_VAL; j += i) {
if (spf[j] == 0) spf[j] = i;
ll lb(ll n){
return n&(-n);
}
int main(){
ci>>n;
for(ll i{1};i<=n;i++){
ci>>a[i];
}
for(ll i{1};i<(1<<(n));i++){
ll now{i};
ll san{};
for(ll j{0};j<=n;j++){
if((1<<j)&i){
sa[++san]=a[j+1];
}
}
}
}
// 获取数字的质因数分解
std::map<int, int> factorize(int num) {
std::map<int, int> factors;
while (num > 1) {
int factor = spf[num];
factors[factor]++;
num /= factor;
}
return factors;
}
int main() {
sieve(); // 预处理,构建 SPF 表
int n;
std::cin >> n;
std::vector<int> a(n);
// 输入数组
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
// for(ll i{1};i<=san;i++){
// co<<sa[i]<<' ';
// }
// co<<'\n';
}
// 用于存储每个质数的所有指数
std::map<int, std::vector<int>> prime_exponents;
// 遍历每个数字,进行质因数分解
for (int i = 0; i < n; ++i) {
auto factors = factorize(a[i]);
for (auto& [prime, exp] : factors) {
prime_exponents[prime].push_back(exp);
}
}
// 计算结果
long long total_operations = 0;
// 遍历每个质数的贡献
for (auto& [prime, exponents] : prime_exponents) {
// 排序以便找到中位数
std::sort(exponents.begin(), exponents.end());
int m = exponents.size();
int median = exponents[m / 2]; // 中位数
// 计算总操作次数为 |xi - median|
long long sum_operations = 0;
for (int exp : exponents) {
sum_operations += std::abs(exp - median);
sum_operations %= MOD; // 防止溢出
}
// 累加到总操作数
total_operations = (total_operations + sum_operations) % MOD;
}
// 输出最终答案
std::cout << total_operations << std::endl;
return 0;
}