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 ...
随机推荐
- 基于.NetCore开发博客项目 StarBlog - (27) 使用JWT保护接口
前言 这是StarBlog系列在2023年的第二篇更新 这几个月都在忙,更新变得很不勤快,但是拖着不更新我的心里更慌,很久没写,要开头就变得很难 说回正题,之前的文章里,我们已经把博客关键的接口都开发 ...
- 第一个mybatis程序,实现增删改查CRUD
mybatis 介绍 mybatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache迁移到了googlecode,并且改名为MyBatis,2013年11月迁移到Git ...
- 2020-08-23:描述HTTPS和HTTP的区别。
福哥答案2020-08-23: 1.地址区别http:http://开头.https:https://开头. 2.默认端口区别http:端口80.https:端口443. 3.数据传输区别http:明 ...
- 2020-09-17:arp协议缓存过程是怎样的?
福哥答案2020-09-17:#福大大架构师每日一题# [答案来自此链接](https://www.zhihu.com/question/421513153) ARP(Address Resoluti ...
- 2022-01-03:比如arr = {3,1,2,4}, 下标对应是:0 1 2 3, 你最开始选择一个下标进行操作,一旦最开始确定了是哪个下标,以后都只能在这个下标上进行操作。 比如你选定1下标,
2022-01-03:比如arr = {3,1,2,4}, 下标对应是:0 1 2 3, 你最开始选择一个下标进行操作,一旦最开始确定了是哪个下标,以后都只能在这个下标上进行操作. 比如你选定1下标, ...
- 2021-08-04:给定一个字符串str,当然可以生成很多子序列。返回有多少个子序列是回文子序列,空序列不算回文。比如,str = “aba”,回文子序列:{a}、{a}、 {a,a}、 {b}、{
2021-08-04:给定一个字符串str,当然可以生成很多子序列.返回有多少个子序列是回文子序列,空序列不算回文.比如,str = "aba",回文子序列:{a}.{a}. {a ...
- drf——序列化之source(了解)、定制字段的两种方式(重要)、多表关联反序列化保存、反序列化字段校验、ModelSerializer使用
1 序列化高级用法之source(了解) # 1.创建了5个表(图书管理的5个) # 2.对book进行序列化 # 总结:source的用法 1.修改前端看到的字段key值--->source指 ...
- k8s资源对象(二)
Configmap和Secret资源介绍 secret和configmap资源都是通过挂载的方式将对应数据挂载到容器内部环境中去使用,两者的使用没有太多的不同 ,configmap资源通常用于为pod ...
- CodeQl lab learn
step-3 query a function named strlen import cpp from Function f where f.getName() = "strlen&quo ...
- 没用,随便写的(Dec_8_2022)
import numpy as np from PIL import Image import pandas as pd import matplotlib.pyplot as plt # 第一个 # ...