\(\mathcal{Description}\)

  Link.

  令 \(f\) 为 \(\text{Fibonacci}\) 数列,给定 \(\{a_n\}\),求:

\[\operatorname{lcm}\{f_{a_1},f_{a_2},\cdots,f_{a_n}\}\bmod(10^9+7)
\]

  \(n\le5\times10^4\),\(a_i\le10^6\)。

\(\mathcal{Solution}\)

  你得知道:

\[\gcd(f_i,f_j)=f_{\gcd(i,j)}\tag1
\]
\[\operatorname{lcm}(S)=\prod_{T\subseteq S\land T\not=\varnothing}\gcd(T)^{(-1)^{|T|+1}}\tag2
\]

  \((1)\) 老经典的结论了;\((2)\) 本质上是一个 \(\text{Min-Max}\) 反演。

  记 \(F=\{f_{a_n}\},S=\{a_n\},m=\max(S)\),开始推导:

\[\begin{aligned}
\operatorname{lcm}(F)&=\prod_{T\subseteq F\land T\not=\varnothing}\gcd(T)^{(-1)^{|T|+1}}\\
&=\prod_{T\subseteq S\land T\not=\varnothing}f_{\gcd(T)}^{(-1)^{|T|+1}}\\
&=\prod_{d=1}^mf_d^{\sum_{T\subseteq S\land T\not=\varnothing\land\gcd(T)=d}(-1)^{|T|+1}}
\end{aligned}
\]

  记 \(f_d\) 的指数为 \(g(d)\),令 \(h(d)=\sum_{T\subseteq S\land T\not=\varnothing\land d|\gcd(T)}(-1)^{|T|+1}=1-\sum_{T\subseteq S\land d|\gcd(T)}(-1)^{|T|}\)。设有 \(c_d\) 个 \(a_x\) 是 \(d\) 的倍数,那么:

\[\sum_{T\subseteq S\land d|\gcd(T)}(-1)^{|T|}=\sum_{s=0}^{c_d}\binom{c_d}s(-1)^s
\]

  二项式展开逆用,后式为 \((1-1)^{c_d}=[c_d=0]\),所以 \(h(d)=[c_d\not=0]\)。最后利用 \(h\) 反演出 \(g\):

\[g(d)=\sum_{d|n}h(n)\mu(\frac{n}d)
\]

  \(\mathcal O(n\ln n)\) 把 \(g\) 求出来就好。

\(\mathcal{Code}\)

/* Clearink */

#include <cstdio>

inline int rint () {
int x = 0; int f = 1; char s = getchar ();
for ( ; s < '0' || '9' < s; s = getchar () ) f = s == '-' ? -f : f;
for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
return x * f;
} inline void wint ( int x ) {
if ( 9 < x ) wint ( x / 10 );
putchar ( x % 10 ^ '0' );
} const int MAXN = 5e4, MAXA = 1e6, MOD = 1e9 + 7;
int pn, pr[MAXA + 5], mu[MAXA + 5];
int n, a[MAXN + 5], fib[MAXA + 5], indx[MAXA + 5];
bool buc[MAXA + 5], vis[MAXA + 5]; inline int qkpow ( int a, int b, const int p = MOD ) {
int ret = 1; b = ( b % ( p - 1 ) + ( p - 1 ) ) % ( p - 1 );
for ( ; b; a = 1ll * a * a % p, b >>= 1 ) ret = 1ll * ret * ( b & 1 ? a : 1 ) % p;
return ret;
} inline void init ( const int n ) {
mu[1] = 1;
for ( int i = 2; i <= n; ++ i ) {
if ( !vis[i] ) mu[pr[++ pn] = i] = -1;
for ( int j = 1, t; j <= pn && ( t = i * pr[j] ) <= n; ++ j ) {
vis[t] = true;
if ( !( i % pr[j] ) ) break;
mu[t] = -mu[i];
}
}
fib[1] = 1;
for ( int i = 1; i <= n; ++ i ) {
if ( i > 1 ) fib[i] = ( fib[i - 1] + fib[i - 2] ) % MOD;
for ( int j = i; j <= n; j += i ) {
buc[i] |= buc[j];
}
}
for ( int i = 1; i <= n; ++ i ) {
for ( int j = 1, t = n / i; j <= t; ++ j ) {
indx[i] += mu[j] * buc[i * j];
}
}
} int main () {
n = rint ();
int mxa = 0;
for ( int i = 1; i <= n; ++ i ) {
buc[a[i] = rint ()] = true;
if ( mxa < a[i] ) mxa = a[i];
}
init ( mxa );
int ans = 1;
for ( int i = 1; i <= mxa; ++ i ) {
ans = 1ll * ans * qkpow ( fib[i], indx[i] ) % MOD;
}
wint ( ans ), putchar ( '\n' );
return 0;
}

\(\mathcal{Details}\)

  对 \(\text{Min-Max}\) 要敏感一点呐……

Solution -「51nod 1355」斐波那契的最小公倍数的更多相关文章

  1. 【51nod 1355】 斐波那契数的最小公倍数

    题目 51nod的数学题都还不错啊 首先直接算显然是没有办法算的,因为\(fib\)的lcm这个东西还是太鬼畜了 我们考虑到\(fib\)数列的一个非常好的性质是\(gcd(fib_i,fib_{j} ...

  2. POJ 3070 + 51Nod 1242 大斐波那契数取余

    POJ 3070 #include "iostream" #include "cstdio" using namespace std; class matrix ...

  3. 【51nod1355】斐波那契的最小公倍数(min-max容斥)

    [51nod1355]斐波那契的最小公倍数(min-max容斥) 题面 51nod 题解 显然直接算还是没法算的,所以继续考虑\(min-max\)容斥计算. \[lcm(S)=\prod_{T\su ...

  4. LOJ 3184: 「CEOI2018」斐波那契表示法

    题目传送门:LOJ #3184. 题意简述: 题目说得很清楚了. 题解: 首先需要了解「斐波那契数系」为何物. 按照题目中定义的斐波那契数列 \(F_n\),可以证明,每个非负整数 \(n\) 都能够 ...

  5. 「洛谷P1306」斐波那契公约数 解题报告

    P1306 斐波那契公约数 题目描述 对于Fibonacci数列:1,1,2,3,5,8,13......大家应该很熟悉吧~~~但是现在有一个很"简单"问题:第n项和第m项的最大公 ...

  6. 51nod 1355 - 斐波那契的最小公倍数(Min-Max 容斥+莫比乌斯反演)

    vjudge 题面传送门 首先我们知道斐波那契数列的 lcm 是不太容易计算的,但是它们的 gcd 非常容易计算--\(\gcd(f_x,f_y)=f_{\gcd(x,y)}\),该性质已在我的这篇博 ...

  7. 51Nod——T 1242 斐波那契数列的第N项

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1242 基准时间限制:1 秒 空间限制:131072 KB 分值: 0  ...

  8. [51nod1355] 斐波那契的最小公倍数

    Description 给定 \(n\) 个正整数 \(a_1,a_2,...,a_n\),求 \(\text{lcm}(f_{a_1},f_{a_2},...,f_{a_n})\).其中 \(f_i ...

  9. Solution -「51nod 1514」美妙的序列

    \(\mathcal{Description}\)   Link.   称排列 \(\{p_n\}\) 美妙,当且仅当 \((\forall i\in[1,n))(\max_{j\in[1,i]}\{ ...

随机推荐

  1. react中Fragment组件

    什么是Fragment?在我们定义组件的时候return里最外层包裹的div往往不想渲染到页面,那么就要用到我们的Fragment组件了,具体使用如下: import React, { Compone ...

  2. 获取js代码运行的时间

    console.time('yue') //代码部分 console.timeEnd('yue')

  3. Anaconda3+CUDA10.1+CUDNN7.6+TensorFlow2.6安装(Ubuntu16)

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  4. fastjson字符串转JSON的$ref问题

    先说结论: fastjson在把对象转换成字符串的时候,如果遇到相同的对象的时候,默认开启引用检测将相同的对象写成引用的形式. 官网文档:https://github.com/alibaba/fast ...

  5. 微信小程序云开发指南

    一.初识云开发 官方文档 小程序·云开发是微信团队联合腾讯云推出的专业的小程序开发服务. 开发者可以使用云开发快速开发小程序.小游戏.公众号网页等,并且原生打通微信开放能力. 开发者无需搭建服务器,可 ...

  6. 搭建服务器之www-向外提供视频服务by html5 video标签

    搭建好www服务器,主要目的有两个一个是试验下,另一个是想给女朋友个惊喜,给她个带视频的网页,嘿嘿当前测试下相应功能. 1,采用html5的视频功能:bideo标签. 源码如下: <!docty ...

  7. C++构造函数语义学(三)(基于C++对象模型)

    带有虚基类的情况. 1 #include<iostream> 2 using namespace std; 3 class X 4 { 5 public: 6 int i; 7 }; 8 ...

  8. JVM专题2: JVM内存结构

    合集目录 JVM专题2: JVM内存结构 Java 内存分配 JVM 内存结构 The JVM is an abstract computing machine that enables a comp ...

  9. Vue之watch监听对象中某个属性的方法

    新建 userinfo = { name: "小明",  age: "18", } vue中watch监听name的方法 1. 可以结合计算属性的方法实现 { ...

  10. Linux 配置 dubbo 和 dubbo的简单介绍。

    一.是么是  dubbo? 一.dubbo? 1.因为项目之间需要相互调用,达到某种预期的结果 1.1 restful? 门户网站必须要知道用户的登录状态,但是用户的登录状态在登录项目中,所以门户网站 ...