2627: JZPKIL

题意:求
\[ \sum_{i=1}^n (n,i)^x [i,n]^y,\ [i,n] = lcm(i,n) \]
\(n \le 10^{18},\ x,y\le 3000\)


本题带来了一种新技巧,n太大,转化成一个积性函数然后求这个积性函数,质因子分解利用积性,这养只与质因子的数量和指数有关

官方题解清橙上有

首先套路推♂倒
\[ n^y \sum_{d \mid n} d^x \sum_{e \mid \frac{n}{d}} \mu(e) e^y \sum_{i=1}^{\frac{n}{de}} i^{y+1-k} \\ \]
这里使用\(D=de\)然后整除分块并不好做

代入伯努利数,交换求和顺序
\[ \frac{n^y}{y+1} \sum_{k=0}^y \binom{y+1}{k} B_k^+ \sum_{d \mid n} d^x \sum_{e \mid \frac{n}{d}} \mu(e) e^y \sum_{i=1}^{\frac{n}{de}} i^{y+1-k} \\ \]
后面那块就是\((id^x *( (\mu \cdot id^y) * id^z)(n) = ( (\mu \cdot id^y) * id^x * id^z)(n)\)

考虑求这个积性函数

用Pollard-rho质因子分解n,然后求

\(( (\mu \cdot id^y) * id^x * id^z)(p^c)\)

这个很好求,\(\mu\)那里只能是\(1,p\),剩下的直接\(O(c)\)计算就行了

质因子个数和指数都是log级的,所以复杂度大约是\(O(y^2 + n^{\frac{1}{4}}logn+ylog^2n)\)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 3005, P = 1e9+7, mo = P, inv2 = (P+1)/2;
inline int read(){char c=getchar(); int x=0,f=1;while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;
}namespace qwq {ll mul(ll a, ll b, ll P) {ll t = (a * b - (ll) ((long double) a / P * b + 0.5) * P);return t<0 ? t+P : t;}ll Pow(ll a, ll b, ll P) {ll ans = 1; a %= P;for(; b; b>>=1, a = mul(a, a, P)) if(b&1) ans = mul(ans, a, P);return ans;}bool witness(ll a, ll n, ll u, int t) {ll x = Pow(a, u, n), y = x;while(t--) {x = mul(x, x, n);if(x == 1 && y != 1 && y != n-1) return true;y = x;}return x != 1;}int p[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23};bool m_r(ll n) {if(n == 2) return true;if(n <= 1 || ~n&1) return false;ll u = n-1, t = 0;while(~u&1) u >>= 1, t++;for(int i=0; i<9; i++) {if(p[i] == n) return true;if(witness(p[i], n, u, t)) return false;}return true;}ll gcd(ll a, ll b) {return !b ? a : gcd(b, a%b);}ll _rho(ll n, ll c) {int k = 2; ll x = rand()%n, y = x, d = 1;for(int i=1; d==1; i++) {x = (mul(x, x, n) + c) %n;d = gcd(n, x>y ? x-y : y-x);if(i == k) y = x, k <<= 1;}return d;}ll d[N];void p_r(ll n) {if(n == 1) return;if(m_r(n)) {d[++d[0]] = n; return;}ll t = n;while(t == n) t = _rho(n, rand() % (n-1) + 1);p_r(t); p_r(n/t);}
} using qwq::d;ll Pow(ll a, ll b) {ll ans = 1; a %= P;for(; b; b>>=1, a=a*a%P)if(b&1) ans=ans*a%P;return ans;
}int b[N];
ll inv[N], fac[N], facInv[N];
inline ll C(int n, int m) {return fac[n] * facInv[m] %P * facInv[n-m] %P;}
void init(int n) {inv[1] = fac[0] = facInv[0] = 1;for(int i=1; i<=n+1; i++) {if(i != 1) inv[i] = (P - P/i) * inv[P%i] %P;fac[i] = fac[i-1] * i %P;facInv[i] = facInv[i-1] * inv[i] %P;}b[0] = 1; b[1] = P-inv2;for(int m=2; m<=n; m++) if(!(m&1)) {for(int k=0; k<=m-1; k++) b[m] = (b[m] - C(m+1, k) * b[k]) %P;b[m] = b[m] * Pow(C(m+1, m), P-2) %P;if(b[m] < 0) b[m] += P;}b[1] = inv2;
}struct meow{ll p; int k;} a[N]; int m;ll p1[N], p2[N];
void solve(ll n, int x, int y) {d[0] = 0; qwq::p_r(n); sort(d+1, d+d[0]+1);m = 0; a[++m] = (meow){d[1], 1};for(int i=2; i<=d[0]; i++) {if(d[i] == d[i-1]) a[m].k++;else a[++m] = (meow){d[i], 1};}//for(int i=1; i<=m; i++) printf("factor %d  %lld %d\n", i, a[i].p, a[i].k);ll ans = 0;for(int k=0; k<=y; k++) { ll t = C(y+1, k) * b[k] %mo; int z = y + 1 - k;for(int i=1; i<=m; i++) {ll p = a[i].p, t1 = 0, t2 = 0; int c = a[i].k;p1[0] = 1; ll u = p1[1] = Pow(p, x); p2[0] = 1; ll v = p2[1] = Pow(p, z);for(int j=2; j<=c; j++) p1[j] = p1[j-1] * u %mo, p2[j] = p2[j-1] * v %mo;for(int j=0; j<=c; j++) t1 = (t1 + p1[j] * p2[c-j]) %mo;for(int j=0; j<c; j++)  t2 = (t2 + p1[j] * p2[c-1-j]) %mo;t2 = (mo - Pow(p, y)) * t2 %mo; t = t * (t1 + t2) %mo;}ans = (ans + t) %mo;}ans = ans * Pow(n, y) %mo * Pow(y+1, mo-2) %mo;printf("%lld\n", ans);
}int x, y; ll n;int main() {freopen("in", "r", stdin);init(3001);int T = read();while(T--) {scanf("%lld", &n); x = read(); y = read();solve(n, x, y);}
}

转载于:https://www.cnblogs.com/candy99/p/6782891.html

bzoj 2627: JZPKIL [伯努利数 Pollard-rho]相关推荐

  1. 64位以内Rabin-Miller 强伪素数测试和Pollard rho 因数分解解析

    在求解POJ1811题Prime Test中应用到的两个重要算法是Rabin-Miller强伪素数测试和Pollard r因数分解算法.前者可以在的时间内以很高的成功概率判断一个整数是否是素数.后者可 ...

  2. 整数的素因子分解:Pollard rho method

    参考: 1.CLRS<算法导论> 2.http://www.csh.rit.edu/~pat/math/quickies/rho/#algorithm Pollard rho方法是随机算法 ...

  3. 因数分解 Pollard rho

    因数分解 Pollard rho 算法思路 随机生成两个数a,ba,ba,b,然后求gcd⁡(n,a−b)\gcd\pod{n,a-b}gcd(n,a−b),如果其值不为111,则这个数就是nnn的一 ...

  4. c语言用rho函数求复数模长,Pollard Rho 算法简介

    $\text{update 2019.8.18}$ 由于本人将大部分精力花在了cnblogs上,而不是洛谷博客,评论区提出的一些问题直到今天才解决. 下面给出的Pollard Rho函数已给出散点图. ...

  5. 大整数分解——Pollard Rho算法

    延续上一篇,这次来讲一讲大整数分解算法的应用. 要解决的问题很简单,对一个整数进行分解质因数. 首先还是效率非常低的暴力算法,相信大家都会,不多提. 和上次一样,当数达到非常大的时候,分解将变得非常困 ...

  6. 素数判定质因数分解(数论)(Miller Rabin)(Pollard Rho)

    太玄学了! 我真的被概率的魅力折服了.此前我认为1便是1,0.9999999999-便是0.9999999999-. 但实际上它们有着千丝万缕的关系. 试想,如果一件事发生的概率是0.99999999 ...

  7. BZOJ 5330 Luogu P4607 [SDOI2018]反回文串 (莫比乌斯反演、Pollard Rho算法)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=5330 (Luogu) https://www.luogu.org/prob ...

  8. 简述大数分解算法Pollard Rho和Pollard p-1

    大数分解问题其实至今都是一个世界级难题,最常见的分解法是从2一直找到sqr(N),作为一个密码学专业的学生,每次看到别人这么做来进行因子分解,自己都控制不住想要制止他,因为这个算法的效率简直太太太太太 ...

  9. 数学--数论--随机算法--Pollard Rho 大数分解算法 (带输出版本)

    RhoPollard Rho是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:MillerRabinMillerRabin素数测试. 操作流程 首先,我们先用MillerRabinMille ...

最新文章

  1. 基于FPGA的目标点的提取与定位系统设计
  2. BugkuCTF-Misc:想蹭网先解开密码
  3. 漫步数学分析七——集合的闭包
  4. Levmar使用小结
  5. ik分词器 分词原理_ElasticSearch 集成Ik分词器
  6. oracle数据泵能增量吗,Oracle12c中数据泵新特性之功能增强(expdp, impdp)
  7. 列车停站方案_高速铁路列车停站方案与运行图协同优化理论和方法
  8. 硬件开发学习需要掌握的基础知识
  9. vue 中如何引入字体(思源黑体)
  10. SpringDataJPA调用存储过程实例
  11. Kafka的消息可靠性(防止消息丢失)
  12. Error:(292, 40) java: -source 1.5 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符) ........
  13. 2021微信大数据挑战赛正式启动报名!
  14. QlikView处理数据
  15. 东北大学OJ-1208: 实验2-7 :计算ASCII码值并输出
  16. mysq coun(*)时为啥这么慢
  17. Settings学习
  18. Go语言结构体指针为nil时的小坑
  19. 笔记本电脑WIFI图标突然不显示的解决办法
  20. 《伴我汽车》后台管理系统开发笔记 下

热门文章

  1. java向上和向下的区别_Java的向上和向下转型
  2. how to switch between python3.5 and python3.6
  3. PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization
  4. 高斯公式,斯克托斯公式
  5. DG Lecture 2 part 2: points, vectors, directional derivative
  6. QTCreator快捷键
  7. 论文阅读:Natural Language Processing Advancements By Deep Learning: A Survey
  8. loss函数之MultiMarginLoss, MultiLabelMarginLoss
  9. recvfrom函数 非阻塞_那些年让你迷惑的阻塞、非阻塞、异步、同步
  10. hdu 1818 It's not a Bug, It's a Feature!(位运算+bfs优先队列)