Codeforces 1855B:Longest Divisors Interval 最长的连续约数区间
1855B.Longest Divisors Interval
Description:
- 对于一个整数 \(n\) \((1\leq n \leq 10^{18})\),找到一段最长的区间\([l,r]\),使得区间内所有数均为 \(n\) 的约数。
Analysis:
- 如果 \(n\)是一个奇数(非 \(2\)的倍数),由于 \(odd = odd \times odd\),则不可能有连续的两个整数均为 \(n\) 的约数;
- 推广:连续3个整数中必有一个是3的倍数,连续x个整数中必有x的倍数
- 若区间 \([l,r]\) 成立,则区间 \([1,r-l+1]\) 也成立(可以通过取模运算转化),故只需从1开始找到第一个(最小的)\(x\) (\(x\)不是\(n\)的约数),则 \(ans = x-1\)
- (补充)关于枚举边界的确定:由唯一分解定理 \(n=p_1^{\alpha_1}p_2^{\alpha_2}···p_k^{\alpha_k}\),可对 \(1e18\) 粗略考虑,已知在 \(\alpha_1=\alpha_2=···=\alpha_k=1\) 的条件下,连续质数相乘:\(p_k=47\)时,\(n\approx6e17\);\(p_k=53,n\approx1e19\)。故在\(\alpha\geq1\)时,\(53\) 即为可行的枚举边界。
// 边界验证
init(); //初始化素数筛
ull res = 1;
for(int i=1;i<=53;i++) {
if(prime[i]) {
res *= i;
cout << "素数:" << i << " " << "res: " << res << endl;
}
}
素数:2 res: 2
素数:3 res: 6
素数:5 res: 30
素数:7 res: 210
素数:11 res: 2310
素数:13 res: 30030
素数:17 res: 510510
素数:19 res: 9699690
素数:23 res: 223092870
素数:29 res: 6469693230
素数:31 res: 200560490130
素数:37 res: 7420738134810
素数:41 res: 304250263527210
素数:43 res: 13082761331670030
素数:47 res: 614889782588491410
素数:53 res: 14142414403480493114
Solution:
void solve() {
ll n; cin >> n;
for(int i=1;i<=55;i++) {
if(n % i != 0) {
cout << i-1 << endl;
return ;
}
}
}
Codeforces 1855B:Longest Divisors Interval 最长的连续约数区间的更多相关文章
- 【leetcode】1124. Longest Well-Performing Interval
题目如下: We are given hours, a list of the number of hours worked per day for a given employee. A day i ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- [LeetCode] Longest Line of Consecutive One in Matrix 矩阵中最长的连续1
Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horiz ...
- leecode 978. Longest Turbulent Subarray(最长连续波动序列,DP or 滚动数组)
传送门:点我 978. Longest Turbulent Subarray A subarray A[i], A[i+1], ..., A[j] of A is said to be turbule ...
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- [Leetcode] Longest consecutive sequence 最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)
Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...
- Leetcode 5. Longest Palindromic Substring(最长回文子串, Manacher算法)
Leetcode 5. Longest Palindromic Substring(最长回文子串, Manacher算法) Given a string s, find the longest pal ...
- [LeetCode] 516. Longest Palindromic Subsequence 最长回文子序列
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the ma ...
- 76.Longest Consecutive Sequence(最长的连续序列)
Level: Hard 题目描述: Given an unsorted array of integers, find the length of the longest consecutive ...
随机推荐
- 2023-04-19:给定一个非负数组arr 任何两个数差值的绝对值,如果arr中没有,都要加入到arr里 然后新的arr继续,任何两个数差值的绝对值,如果arr中没有,都要加入到arr里 一直到ar
2023-04-19:给定一个非负数组arr 任何两个数差值的绝对值,如果arr中没有,都要加入到arr里 然后新的arr继续,任何两个数差值的绝对值,如果arr中没有,都要加入到arr里 一直到ar ...
- 2020-12-12:现场写代码,把CPU打满,java和go都行,并解释为什么。
福哥答案2020-12-12: 现在的电脑一般是多核的,单个for循环cpu是不会打满的. 我的电脑是四核八线程的,不管是java还是go,6个for循环就能把cpu打满,4个和5个cpu打不满. 为 ...
- 2022-08-31:以下go语言代码输出什么?A:江苏;B:v[“province“]取值错误;C:m.Store存储错误;D:不知道。 package main import ( “fm
2022-08-31:以下go语言代码输出什么?A:江苏:B:v["province"]取值错误:C:m.Store存储错误:D:不知道. package main import ...
- 2022-06-03:a -> b,代表a在食物链中被b捕食, 给定一个有向无环图,返回这个图中从最初级动物到最顶级捕食者的食物链有几条。 来自理想汽车。
2022-06-03:a -> b,代表a在食物链中被b捕食, 给定一个有向无环图,返回这个图中从最初级动物到最顶级捕食者的食物链有几条. 来自理想汽车. 答案2022-06-03: 拓扑排序. ...
- 2021-01-09:linux中,某一个实时日志通过什么命令查?
福哥答案2020-01-09:[答案来自此链接:](https://www.zhihu.com/question/438536200)1.tailtail -f首先就是 tail -f,tail 命令 ...
- 2021-03-19:给定一个二维数组matrix,其中的值不是0就是1,返回全部由1组成的最大子矩形,内部有多少个1。
2021-03-19:给定一个二维数组matrix,其中的值不是0就是1,返回全部由1组成的最大子矩形,内部有多少个1. 福大大 答案2021-03-19: 按行遍历二维数组,构造直方图. 单调栈,大 ...
- Grafana系列-统一展示-8-ElasticSearch日志快速搜索仪表板
系列文章 Grafana 系列文章 概述 我们是基于这篇文章: Grafana 系列文章(十二):如何使用 Loki 创建一个用于搜索日志的 Grafana 仪表板, 创建一个类似的, 但是基于 El ...
- Selenium - 浏览器操作
Selenium - 浏览器操作 获取浏览器信息 from selenium import webdriver driver = webdriver.Chrome() driver.get(" ...
- OneForAll下载安装以及环境配置
python-3.9.7-amd64 OneForAll-master python安装以及插件安装 首先下载python解压到电脑c盘在c盘中创建一个工具文件夹,然后下载OneForAll-mast ...
- 系统MySQL服务无法启动报错1067的四种解决方法win7系统MySQL服务无法启动报错1067的四种解决方法
有些win7系统用户在登陆mysql或者重装mysql时出现"无法启动MYSQL服务,错误1067",而且重启.修复注册表都没办法解决问题.那么遇到MySQL服务无法启动问 ...