传送门

Description

Let \((1+\sqrt2)^n=e(n)+f(n)\cdot\sqrt2\) , both \(e(n)\) and \(f(n)\) are integers

Let \(g(n)\) be the gcd of \(f(1),f(2),...,f(n)\)

given \(n\), \(p\), where \(p\) is a prime number

Calculate the value of 
\[  \sum_{i=1}^{n}i\cdot g(i) \ \ \ \ mod \ p \]
 \(T\leq 210 ,\sum n\leq 3×10^6\)

Solution

\[ f(n)=2f(n-1)+f(n-2),f(0)=1,f(1)=1 \]

Similar to the \(Fibonacci\) sequence, we have
\[  gcd(f(a),f(b))=f(gcd(a,b)) \]
 It's hard to evaluate LCM directly,but we can get it by maximum inversion
\[  lcm(S)=\prod_{T⊆S,T≠∅}gcd(T)^{(−1)^{|T|−1}} \]
 so we can find that
\[  g(n)=\prod_{T⊆S,T≠∅}f(gcd(T))^{(−1)^{|T|−1}} \]
 The next step is the most important.

construct a function \(h\) ,which satisfies
\[  f(n)=\prod_{d|n}h(d) \]
 we can calculate \(h(1...n)\) easily by \(O(n\log n)\)

and 
\[  \begin{equation}  \begin{split}  g(n)&=\prod_{d=1}^n h(d)^{∑_{T⊆S,T≠∅,d|gcd(T)}(−1)^{|T|+1}}\\  &=\prod_{d=1}^nh(d)  \end{split}  \end{equation} \]

Code

#include<bits/stdc++.h>
#define ll long long
#define reg register
#define db double
using namespace std;
inline int read()
{int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}return x*f;
}
const int MN=1e6+5;
int f[MN],h[MN],n,P,ans;
int Mul(int x,int y){return 1ll*x*y%P;}
int Add(int x,int y){return (x+y)%P;}
int fpow(int x){int r=1,m=P-2;for(;m;m>>=1,x=Mul(x,x))if(m&1)r=Mul(r,x);return r;}
int main()
{int T=read();while(T--){n=read(),P=read();reg int i;f[0]=0;h[0]=h[1]=f[1]=1;for(i=2;i<=n;++i) h[i]=1,f[i]=Add(Mul(f[i-1],2),f[i-2]);for(i=2;i<=n;++i){h[i]=Mul(f[i],fpow(h[i]));for(int j=i<<1;j<=n;j+=i) h[j]=Mul(h[j],h[i]);}for(ans=0,i=1;i<=n;++i) h[i]=Mul(h[i],h[i-1]),ans=Add(ans,Mul(h[i],i));printf("%d\n",ans);}return 0;
}

Blog来自PaperCloud,未经允许,请勿转载,TKS!

转载于:https://www.cnblogs.com/PaperCloud/p/10955865.html

[bzoj 4833]最小公倍佩尔数相关推荐

  1. [数论 反演] BZOJ 4833 最小公倍佩尔数

    当时比赛时灵机一动 把gigi−1g_i\over g_{i-1}喂给了OEIS 然后就找到了 233 就是这个咯 然后就水过去了 题解?题解我还没看 先挖个坑 UPD:跟这个题是一毛一样的咯 #in ...

  2. 【BZOJ4833】最小公倍佩尔数(min-max容斥)

    [BZOJ4833]最小公倍佩尔数(min-max容斥) 题面 BZOJ 题解 首先考虑怎么求\(f(n)\),考虑递推这个东西 \((1+\sqrt 2)(e(n-1)+f(n-1)\sqrt 2) ...

  3. bzoj 4833: [Lydsy1704月赛]最小公倍佩尔数

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4833 推推式子,可以得到f(n)=2*f(n-1)+f(n-2) 然后就可以按照这个来做了 ...

  4. BZOJ 4833: [Lydsy1704月赛]最小公倍佩尔数(数论 + 最值反演)

    题面 令 \({(1+\sqrt 2)}^n=e(n)+f(n)*\sqrt2\) ,其中 \(e(n),f(n)\) 都是整数,显然有 \({(1-\sqrt 2)}^n=e(n)-f(n)*\sq ...

  5. 【bzoj 4833】[Lydsy1704月赛]最小公倍佩尔数

    Description 令 $(1+\sqrt 2)^n=e(n)+\sqrt 2\cdot f(n)$ ,其中 $e(n),f(n)$ 都是整数,显然有 $(1-\sqrt 2)^n=e(n)-\s ...

  6. BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数-数论

    传送门 题意: 令(1+2–√)n=e(n)+f(n)∗2–√(1+2)n=e(n)+f(n)∗2(1+\sqrt2)^n=e(n)+f(n)*\sqrt2,其中e(n),f(n)e(n),f(n)e ...

  7. BZOJ4833 [Lydsy1704月赛]最小公倍佩尔数

    题意 已知\(e_n+\sqrt2f_n=(1+\sqrt2)^n\),\(e_n-\sqrt2f_n=(1-\sqrt2)^n\),\(g_n=lcm_{i=1}^nf_i\),求\(\sum_{i ...

  8. BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数

    Problem 传送门 Sol 容易得到 fn=en−1+fn−1,en−1=fn−1+en−1,f1=e1=1f_n=e_{n-1}+f_{n-1},e_{n-1}=f_{n-1}+e_{n-1}, ...

  9. [bzoj4833][数论][min-max容斥]最小公倍佩尔数

    Description 令(1+sqrt(2))n=e(n)+f(n)*sqrt(2),其中e(n),f(n)都是整数,显然有(1-sqrt(2))n=e(n)-f(n)*sqrt(2).令g( n) ...

最新文章

  1. IT人应该具备的几种技能
  2. elasticsearch-php使用scroll深度分页处理数据(附代码)
  3. 牛逼!有人用漫画带你了解 Linux 内核长啥样
  4. 【BZOJ】1076 [SCOI2008]奖励关 期望DP+状压DP
  5. Python中制作词云的WordCloud参数详解
  6. axios (get post请求、头部参数添加)傻瓜式入门axios
  7. matlab里面连接器是什么,连接器
  8. 安装memcache
  9. 【CCCC】L2-020 功夫传人 (25分),,模拟水题,多叉树的存储与遍历
  10. mod_signalwire.c:1009 Next SignalWire adoption
  11. 项目经理如何管理团队
  12. 用C#.NET编写软件注册机
  13. Android安全论文汇集
  14. 为什么计算机播放音乐不响,电脑打开音响,播放音乐为什么没有声音??!!~急急急!!快! 爱问知识人...
  15. 余秋雨 成熟是一种明亮而不刺眼的光辉
  16. 通过LiveNVS(免费使用)集中化管理多个LiveNVR-数据透传摆脱局域网的公网IP限制
  17. 代码角度理解SGX的认证机制(一):本地认证
  18. 含并行连结的网络 GoogLeNet / Inception V3 动手学深度学习v2 pytorch
  19. [Oracle 11g r2(11.2.0.4.0)]集群守护进程gpnp介绍
  20. 【SlowFast复现】SlowFast Networks for Video Recognition复现代码 使用自己的视频进行demo检测

热门文章

  1. SpringMVC @ResponseBody在IE8变下载
  2. 2022-2028全球与中国3-甲基吡啶市场现状及未来发展趋势
  3. java中JAO_JVM内部细节之一:synchronized关键字及实现细节(轻量级锁Lightweight Locking)...
  4. python docx 合并文档 图片_MBT文档模型化生成工具——30倍效率文档撰写工程化方法...
  5. Gif动图怎么改变大小?手把手教你在线修改gif大小
  6. or计算遇到存在零“0”的情况
  7. 关于数据表设计的问题, 是主键 id 作为关联, 还是其他的唯一字段?
  8. 人生有时需要“跳一跳”
  9. 第十二期 U-Boot工作原理 《路由器就是开发板》
  10. python数据分析可视化