diff --git a/src/20241113/T538697.cpp b/src/20241113/T538697.cpp index 4b57304..f061f1a 100644 --- a/src/20241113/T538697.cpp +++ b/src/20241113/T538697.cpp @@ -1,125 +1,38 @@ -// #include -// #include -// #include -// #include -// #include -// #include - -// using int64 = int64_t; - -// template -// void input(Args&&...args){ -// (std::cin>>...>>std::forward(args)); -// } - -// template -// std::remove_cvref_t input(){ -// std::remove_cvref_t t; -// std::cin>>t; -// return t; -// } - -// template -// void print(Args&&...args){ -// (std::cout<<...<(args)); -// } - -// const int64 max_n = 3e5 + 5; - -// int main(){ -// const int64 n = input(), m = input(); - -// const std::array s = [&]()->std::remove_cvref_t{ -// std::remove_cvref_t ret; -// for(const auto &i : std::ranges::views::iota(1, n+1)){ -// input(ret[i]); -// } -// return ret; -// }(); - - -// } - +#include #include -#include -#include -#include -#include -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 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< factorize(int num) { - std::map 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 a(n); - - // 输入数组 - for (int i = 0; i < n; ++i) { - std::cin >> a[i]; + // for(ll i{1};i<=san;i++){ + // co<> 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; } \ No newline at end of file