题目

题目描述
There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations.

Dima is sure that it’ll be great to learn to solve the following problem by the Big Day: You’re given a set AA , consisting of numbers ll , l+1l+1 , l+2l+2 , … , rr ; let’s consider all its kk -element subsets; for each such subset let’s find the largest common divisor of Fibonacci numbers with indexes, determined by the subset elements. Among all found common divisors, Dima is interested in the largest one.

Dima asked to remind you that Fibonacci numbers are elements of a numeric sequence, where F_{1}=1F
1

=1 , F_{2}=1F
2

=1 , F_{n}=F_{n-1}+F_{n-2}F
n

=F
n−1

+F
n−2

for n>=3n>=3 .

Dima has more than half a century ahead to solve the given task, but you only have two hours. Count the residue from dividing the sought largest common divisor by mm .

输入格式
The first line contains four space-separated integers mm , ll , rr and kk (1<=m<=10^{9}; 1<=l<r<=10^{12}; 2<=k<=r-l+1) .

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

输出格式
Print a single integer — the residue from dividing the sought greatest common divisor by mm .

题意翻译
设FF是斐波那契数列,在[l,r][l,r]中选kk个数a_{1}…a_{k}a
1

…a
k

,使得gcd(F_{a_{1}},F_{a_{2}},…,F_{a_{k}})gcd(F
a
1


,F
a
2


,…,F
a
k


)尽可能大。输出对mm取模后的结果。

输入输出样例
输入 #1复制
10 1 8 2
输出 #1复制
3
输入 #2复制
10 1 8 3
输出 #2复制
1

思路

有一个性质gcd(f(a),f(b))=f(gcd(a,b))
那么问题就转化成在区间 [l,r][l,r] 中找 kk 个不同的数字使得这些数字的最大公约数最大。

那么在一个区间 [l,r] 中,有因子 x 的数的数量是 r/x-(l-1)/x个,我们在sqrt® 中寻找 i 和 r/i 的有因子 x 的数的数量是否大于等于 k,记录下最大的一个因子 id,那么最后的答案就是 Fid

代码

#include <bits/stdc++.h>
using namespace std;
char ch,B[1 << 20],*S = B,*T = B;
ll mod,l,r,k;
struct M
{ll a[3][3];M() { memset(a,0,sizeof a); }M operator*(const M &b) const {M res;for(int i = 1; i <= 2; ++i)for(int j = 1; j <= 2; ++j)for(int k = 1; k <= 2; ++k)res.a[i][j] = (res.a[i][j] + 1ll * a[i][k] * b.a[k][j] % mod) % mod;return res;}
} ans,base;
void init() {base.a[1][1] = base.a[1][2] = base.a[2][1] = 1;ans.a[1][1] = ans.a[1][2] = 1;
}
void power(int b) {while (b) {if (b & 1) ans = ans * base;base = base * base;b >>= 1;}
}
void work() {mod = rdll();l = rdll();r = rdll();k = rdll();int id = 0;for(ll i = 1; i * i <= r; ++i){if(r / i - (l - 1) / i >= k){checkmax(id,i);}if(r / (r / i) - (l - 1) / (r / i) >= k){checkmax(id,r / i);}}if(id <= 2) {id = 1 % mod;printf("%lld\n",id);} else {init();power(id - 2);printf("%lld\n",ans.a[1][1] % mod);}
}
int main()
{work();return 0;
}

【CF226C】Anniversary相关推荐

  1. fgo7.27服务器维护,【公告】更新游戏数据资料(7/27 实施)

    [公告]更新游戏数据资料(7/27 实施) 鹅蛋 2021-07-27 18:040 0 834 举行圣晶石召唤(期间限定)『「Fate/Grand Order Fes. 2021 -6th Anni ...

  2. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  3. 【CentOS】利用Kubeadm部署Kubernetes (K8s)

    [CentOS]利用Kubeadm部署Kubernetes (K8s)[阅读时间:约10分钟] 一.概述 二.系统环境&项目介绍 1.系统环境 2.项目的任务要求 三.具体实验流程 1 系统准 ...

  4. 【Spring】框架简介

    [Spring]框架简介 Spring是什么 Spring是分层的Java SE/EE应用full-stack轻量级开源框架,以IOC(Inverse Of Control:反转控制)和AOP(Asp ...

  5. 【C#】类——里式转换

    类是由面对对象程序设计中产生的,在面向结构的程序设计例如C语言中是没有类这个概念的!C语言中有传值调用和传址调用的两种方式!在c语言中,主方法调用方法,通过传递参数等完成一些操作,其中比较常用的的数据 ...

  6. 【C#】Out与ref是干什么的?

    关于return: 1.最后没有写 return 语句的话,表示程序正常退出 2.不需要返回值时,存在return的作用 例子 void main() {return; //return退出该程序的作 ...

  7. 【软件工程】RUP与软件开发5大模型

    软件开发的5大模型 1.瀑布模型:按照人的思维一步一步的开发下去,如果需求分析得当,每个阶段顺利,结果还不错! 2.快速原型模型:后来人们发现,自己不可能一下子就把所有的需求搞清楚,总是在开发的过程中 ...

  8. 【VB】学生信息管理系统5——数据库代码

    这次学生信息管理系统在代码的理解过程中遇到了一些问题.总结如下: 1. sql server的安装过程各个步骤的意思.在安装SQL Server的时候按照网上的步骤,我觉得这个需要学完整个数据库再返回 ...

  9. 白化(预处理步骤)【转】

    白化(预处理步骤)[转] 介绍 我们已经了解了如何使用PCA降低数据维度.在一些算法中还需要一个与之相关的预处理步骤,这个预处理过程称为白化.举例来说,假设训练数据是图像,由于图像中相邻像素之间具有很 ...

最新文章

  1. 洽洽三只松鼠良品铺子,到底谁能笑傲“后坚果时代”?
  2. 百度NeurIPS全球顶会冠军团队,带你7日从零实践强化学习
  3. Serval and Bus
  4. git 常用commands(转)
  5. 学习过程中的一些想法
  6. 使用Webtask.io创建一个简单的REST API端点
  7. SQL - 创建一个学生表,要求有主键约束和非空约束
  8. 第一次使用水晶报表,柱状图的横竖坐标不会定位,怎么办?
  9. 如何在Ubuntu上安装MySQL
  10. python装饰器实现用户密码认证(简单初形)
  11. Docker容器系列教程(三):jenkins环境搭建与插件安装
  12. java 环境变量配置
  13. 如何root安卓手机_2019年安卓手机一键root教程,附科普安卓为何root困难?
  14. 网页视频进度条禁止拖动----解决
  15. 大数据比手势锁靠谱?支付宝回应质疑
  16. 什么是CDN资质?什么情况需要办CDN牌照
  17. Software knowledge Encyclopedia:extjs是一种软件,自动生成行号,支持checkbox全选
  18. C++获取电脑主板唯一标识
  19. html中怎么制作选择头像,网页中的个人头像选择框(转)
  20. SHOW INNODB STATUS(3)

热门文章

  1. Hadoop3.2.1 【 YARN 】源码分析 : ContainerLaunch源码浅析
  2. OpenCV中threshold自动阈值,类似matlab中的graythresh
  3. 《薛兆丰的经济学课》课程总结3--生命有限
  4. 电子白板无法触摸怎么办?
  5. C语言实现逆波兰表达式计算函数(含浮点型、整型混合运算)
  6. 计算机显示在手机桌面上怎么解除,桌面布局已锁定怎么解除 桌面布局已锁定解除办法...
  7. I Need Some Sleep / Eels
  8. 修改了部分原理图后如何更新到pcb
  9. IdentityServer3 v1文档
  10. Unity常用旋转方法