2021 ICPC Gran Premio de Mexico 2da Fecha - F.Flipped Factorization(PN筛)
直接使用PN筛O(nlogn)O(\sqrt n \log n)O(nlogn),注意几个会溢出的乘法。
拟合函数g(x)=1g(x)=1g(x)=1,令f=h∗gf=h*gf=h∗g,易推知:h(p)=0,h(1)=1,h(pk)=f(pk)−f(pk−1)h(p)=0,h(1)=1,h(p^k)=f(p^k)-f(p^{k-1})h(p)=0,h(1)=1,h(pk)=f(pk)−f(pk−1)
Ans=∑i=1n[i∈PN]h(i)⌊ni⌋Ans=\sum_{i=1}^{n}[i\in PN]h(i)\lfloor\frac{n}{i}\rfloorAns=i=1∑n[i∈PN]h(i)⌊in⌋
dfsdfsdfs时更新答案即可。
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#define PII pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define ps push
#define all(a) a.begin(), a.end()
#define pb push_back
#define vec vector
#define str string
using namespace std;
typedef long long ll;const int N = 1e7 + 10;
const int mod = 1e9 + 7;int cnt;ll pr[N];
bitset<N> ok;ll n, sq, ans;ll qpow(ll x, ll n) {ll res = 1LL;for (x %= mod; n; n >>= 1, x = x * x % mod)if (n & 1LL) res = res * x % mod;return res;
}void dfs(ll x, ll h, int num) {ll lim = n / x;ans = (ans + lim % mod * h % mod) % mod;for (int i = num + 1; i <= cnt; i++) {if (1LL * pr[i] * pr[i] > lim) break;ll cur = 1LL * x * pr[i] * pr[i], tmp = n / pr[i];for (int j = 2; cur <= n; j++, cur = cur * pr[i]) {dfs(cur, (qpow(j, pr[i]) - qpow(j - 1, pr[i]) + mod) % mod * h % mod, i);if (cur > tmp) break;}}
}int main() {scanf("%lld", &n), sq = sqrtl(n) + 1;for (int i = 2; i <= sq; i++) {if (!ok[i]) pr[++cnt] = i;for (int j = 1; j <= cnt && 1LL * i * pr[j] <= sq; j++) {ok[i * pr[j]] = 1;if (i % pr[j] == 0) break;}}dfs(1, 1, 0);printf("%lld", ans);return 0;
}
另记
组队训练时一直吊死在Min_25筛上真是不值(如有大佬用这个过了就当我没说),害,以前看PN不太实用(h(pk)h(p^k)h(pk)一般情况要用二维数组存,空间可能直接爆炸),就没学(虽然挺简单的)。
2021 ICPC Gran Premio de Mexico 2da Fecha - F.Flipped Factorization(PN筛)相关推荐
- 【2021 ICPC Gran Premio de Mexico 2da Fecha F】Flipped Factorization 题解
题目大意 设 x x x 的质因数分解为 p 1 c 1 p 2 c 2 ⋯ p m c m p_1^{c_1}p_2^{c_2}\cdots p_m^{c_m} p1c1p2c2⋯pmc ...
- 2021 ICPC Gran Premio de Mexico 2da Fecha(C,D,G,I)
题目 C. Cut the Deck D. Dislike the Raisins G. Grid of Letters I. Integer Multiplicative Persistence C ...
- 训练记录番外篇(2):2022 ICPC Gran Premio de Mexico 2da Fecha
2022 ICPC Gran Premio de Mexico 2da Fecha 2022.10.3 之前训得ak场,个人认为很edu. (顺便一提,可能这个训练记录番外系列的比赛都非常edu,十分 ...
- 2021 ICPC Gran Premio de Mexico 1ra Fecha
C.Cypher Decypher 题意 找 [ i , j ] [i,j] [i,j]区间中有多少个质数 思路 数据范围为 1 ≤ i ≤ j ≤ 1 0 6 1\le i\le j\le 10^6 ...
- 2022 ICPC Gran Premio de Mexico 2da Fecha Final standings - K. Krystalova‘s Trivial Problem
K. Krystalova's Trivial Problem time limit per test1 second memory limit per test256 megabytes input ...
- 2022 ICPC Gran Premio de Mexico 1ra Fecha(一)
今天大部分时间都花在了上一场沈阳站的L题上了,一个树上背包+容斥原理,看了好久才理解,就不硬敲上了,再想几天在写题解.然后今天自己写了场ICPC墨西哥站的 ICPC Gran Premio de Me ...
- 2022 ICPC Gran Premio de Mexico 1ra Fecha 题解
A 线性基 由于数组异或和固定,因此异或和为奇数的位置可以不用考虑,无论如何分,总是只能有1个为奇数,总贡献不变. 考虑异或和为偶数的位置,利用线性基求其中一部分尽可能大的结果,另一部分结果相同. # ...
- 2022 ICPC Gran Premio de Mexico 1ra Fecha (B、D、E、F)
小技巧: stoi(str,0,2) 将从0开始的二进制串转化为十进制串 不是标准函数,慎用(一般应该没问题吧--) 本次补的题应该都是铜.银牌题,可能欧洲场简单很多 D. Different Pas ...
- 2023 ICPC Gran Premio de Mexico 1ra Fecha
待更新 目录 1 A Aliases B Bucket storing D Dynamic Collection E Employees Bonus G Growing game J Jumping ...
- 2022 ICPC Gran Premio de Mexico Repechaje 题解
目录 A. Average Walk(签到) 题意: 思路: 代码: C. Company Layoffs(签到) 题意: 思路: 代码: D. Denji1(模拟/二分) 思路: 代码: K. Ke ...
最新文章
- Nature灵魂拷问:微生物组数据一大堆,如何能改变人类健康?
- linux通配符和正则表达式的区别总结
- 基于人脸识别的商业大数据13
- php 打印测试技巧
- 【ARM】Tiny4412裸板编程之MMU(段 16M)
- web项目的两个创建形式website和webapplication
- 微信小程序 三元运算 checked
- Eclipse、VBA、IE开发者工具 Debug快捷键
- 软工导论 12-13-2 实验任务一
- 【语音编码】基于matlab LPC编解码【含Matlab源码 554期】
- detectron2训练自己的数据集_从零教你训练自己的数据集实现汽车标志识别,汽车品牌识别源码
- 浅析数据结构-图的基本概念
- 用C语言实现C++ 继承与多态
- 如何开启计算机cpu虚拟化,如何开启cpu虚拟化_VMware Workstation 中如何开启CPU 的虚拟化支持?...
- java和数据库时间类型
- HTTPS 和 SSL/TLS 协议:密钥交换(密钥协商)算法及其原理
- sequence和sequencer — UVM
- SharePoint2013简单部署
- 朱棣文 哈佛开学典礼演讲
- 学习java之路之第五周