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 ...
随机推荐
- 再解 [NOI2017] 整数
提供一个来自 CF 大佬 adament 的有趣思路. 首先我们知道的是一个只增加的 \(b\) 进制整数计数器,如果 \(b\) 是常数那么复杂度是均摊 \(O(1)\) 的.证明只需要考虑将 \( ...
- Prism Sample 10 10-CustomRegistrations
作用同上节,这里是用修改注册的方式自定义View和ViewModel的关联. protected override void ConfigureViewModelLocator() { base.Co ...
- 2023-01-09:以下go语言代码输出什么?A:+Inf; B:zero; C:something else; D:doesn‘t compile。 package main import (
2023-01-09:以下go语言代码输出什么?A:+Inf: B:zero: C:something else: D:doesn't compile. package main import ( & ...
- 2020-10-27:go中select的执行流程是什么?
福哥答案2020-10-27: ***[2020-10-27:go中select的执行流程是什么?](https://bbs.csdn.net/topics/398044569)
- 2021-01-01:https加解密机制,你了解多少?
福哥答案2021-01-01:这道题是我被大厂面试的题,但网上的答案太多了,故直接引用. HTTPS(全称:Hyper Text Transfer Protocol over Secure Socke ...
- 2022-02-06:等差数列划分 II - 子序列。 给你一个整数数组 nums ,返回 nums 中所有 等差子序列 的数目。 如果一个序列中 至少有三个元素 ,并且任意两个相邻元素之差相同,则称
2022-02-06:等差数列划分 II - 子序列. 给你一个整数数组 nums ,返回 nums 中所有 等差子序列 的数目. 如果一个序列中 至少有三个元素 ,并且任意两个相邻元素之差相同,则称 ...
- 2021-09-06:给表达式添加运算符。给定一个仅包含数字 0-9 的字符串 num 和一个目标值整数 target ,在 num 的数字之间添加 二元 运算符(不是一元)+、- 或 * ,返回所有
2021-09-06:给表达式添加运算符.给定一个仅包含数字 0-9 的字符串 num 和一个目标值整数 target ,在 num 的数字之间添加 二元 运算符(不是一元)+.- 或 * ,返回所有 ...
- 创建对象create()、批量创建bulk_create()、创建或更新update_or_create()、更新对象update()、更新或创建update_or_create()、删除对象delete()使用filter过滤、判断是否存在exists()、统计个数count()、聚合aggregate()
创建对象create().批量创建bulk_create().创建或更新update_or_create().更新对象update().更新或创建update_or_create().删除对象dele ...
- vernemq 一个可用的入门指南之一:Mac下的安装及使用,使用MQTTX访问verneMQ
因为百度到一篇简书的,不可用,所以写这么一篇,方便后来人 物联网的消息队列技术选型,很多地方会推荐使用VerneMQ,这里做一个安装实验记录,并非推荐. git clone https://githu ...
- Intellij IDEA最新激活码,适合2022,2023和所有版本,永久更新
分享一下 IntelliJ IDEA 2023.1 最新激活注册码,破解教程如下,可免费永久激活,亲测有效,下面是详细文档哦~ 申明:本教程 IntelliJ IDEA 破解补丁.激活码均收集于网络, ...