CF1474-B. Different Divisors

题意:

题目给出你一个\(d\),要求你找出一个数字\(y\),找到的\(y\)至少有四个整数因子并且任意两个因子之间的差至少为\(d\)。


思路:

首先\(1\)是任何数字的因子,任何数自己本身也是自己的一个因子,所以我们只需要找到两个差值不小于\(d\)的数字\(x_1, x_2\),并且\(min(x_1, x_2)\)与\(1\)的差值也不小于\(d\),那么第四个因子就是\(x_1*x_2\),也就是我们要找的\(y\)。所以最终答案就是\(y=1*(1+d)*(1+d+d)\).....吗?这个答案看上去没什么问题,但是再看一遍题目,要求任意两个因子之间的差至少为\(d\),而\(y\)可能还有其他的因子,其他的因子的差可能会小于\(d\),所以这样是不可以的。

但是这并不能说明这个方法是不可取的,如果取到的\(x_1, x_2\)除了\(1\)和它本身没有其他的因子,那么\(y\)也就不会有除了\(1, x_1, x_2, y\)其他的因子了。而\(x_1, x_2\)取质数就可以很好的解决问题了。用质数筛筛出质数,两次二分查找就能找到答案。


AC代码:

#include <cstdio>
#include <algorithm> typedef long long ll; const int Maxn = 30005; bool isPrime[Maxn];
int Prime[Maxn], cnt; void getPrime(int n) {
isPrime[0] = isPrime[1] = true;
for (int i = 2; i <= n; i++) {
if (!isPrime[i]) {
Prime[cnt++] = i;
}
for (int j = 0; j < cnt && i * Prime[j] <= n; j++) {
isPrime[i * Prime[j]] = true;
if (i % Prime[j] == 0) {
break;
}
}
}
} void solve() {
int d;
scanf("%d", &d);
int p1 = (int)(std::lower_bound(Prime, Prime + cnt, 1 + d) - Prime);
int p2 = (int)(std::lower_bound(Prime, Prime + cnt, Prime[p1] + d) - Prime);
ll ans = 1LL * Prime[p1] * Prime[p2];
printf("%lld\n", ans);
} int main() {
getPrime(30000);
int T;
scanf("%d", &T);
while (T--) {
solve();
} return 0;
}

CF1474-B. Different Divisors的更多相关文章

  1. codeforces 27E Number With The Given Amount Of Divisors

    E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...

  2. HDU - The number of divisors(约数) about Humble Numbers

    Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...

  3. Divisors

    计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...

  4. Xenia and Divisors

    Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. hihocoder1187 Divisors

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...

  6. The number of divisors(约数) about Humble Numbers[HDU1492]

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  7. Sum of divisors

    Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...

  8. Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力

    B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...

  9. UVa 294 (因数的个数) Divisors

    题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...

  10. hdu4432 Sum of divisors(数论)

    Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. leetcode 1593. 拆分字符串使唯一子字符串的数目最大(DFS,剪枝)

    题目链接 leetcode 1593. 拆分字符串使唯一子字符串的数目最大 题意: 给你一个字符串 s ,请你拆分该字符串,并返回拆分后唯一子字符串的最大数目. 字符串 s 拆分后可以得到若干 非空子 ...

  2. LeetCode563. 二叉树的坡度

    题目 1 class Solution { 2 public: 3 int ans = 0; 4 int findTilt(TreeNode* root) { 5 postOrder(root); 6 ...

  3. PeleeNet:精修版DenseNet,速度猛增至240FPS | NeurIPS 2018

    PeleeNet是DenseNet的一个变体,没有使用流行的深度可分离卷积,PeleeNet和Pelee仅通过结构上的优化取得了很不错的性能和速度,读完论文可以学到很多网络设计的小窍门.   来源:晓 ...

  4. mysql 1449 : The user specified as a definer ('usertest'@'%') does not exist 解决方法 (grant 授予权限)

    从服务器上迁移数据库到本地localhost 执行  函数  时报错, mysql 1449 : The user specified as a definer ('usertest'@'%') do ...

  5. 白日梦的Elasticsearch实战笔记,32个查询案例、15个聚合案例、7个查询优化技巧。

    目录 一.导读 三._search api 搜索api 3.1.什么是query string search? 3.2.什么是query dsl? 3.3.干货!32个查询案例! 四.聚合分析 4.1 ...

  6. Vue 3自定义指令开发

    本文由葡萄城技术团队原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 什么是指令(directive) 在Angular和Vue中都有Direct ...

  7. Vue之事件绑定

    Vue事件绑定 点击事件 @click="事件名" or v-on:click="事件名" 结构部分: <el-button type="pri ...

  8. 为什么Go自带的日志默认输出到os.Stderr?

    为什么Go自带的日志默认输出到os.Stderr? - 知乎 https://www.zhihu.com/question/67629357 Note that the Go runtime writ ...

  9. Lucene 查询原理 传统二级索引方案 倒排链合并 倒排索引 跳表 位图

    提问: 1.倒排索引与传统数据库的索引相比优势? 2.在lucene中如果想做范围查找,根据上面的FST模型可以看出来,需要遍历FST找到包含这个range的一个点然后进入对应的倒排链,然后进行求并集 ...

  10. SQL解析工具

    面对复杂的SQL可用这个SQL解析工具,分析出用到了哪些表哪些字段: http://107.170.101.241:8080/getTableColumn/