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. 【ORA】ORA-01078和LRM-00109 解决方法

    今天切换到asm实例的时候,发现是一个空实例,尝试启动实例,结果报错ORA-01078和LRM-00109 SQL> startupORA-01078: failure in processin ...

  2. 【RAC】oracle11g r2 rac环境删除节点步骤

    1.移除数据库实例 如果节点运行了service首先需要删除service使用dbca图形化界面删除节点依次选择 Real Application Clusters -- > Instance ...

  3. kubernets之就绪探针

    一 介绍就绪探针 1.1  开始介绍就绪探针之前,让我们来提问几个问题?第一,在sevice这章我们了解到, 当流量从Ingress被转发到服务,然后服务从其维护当Endponits 里面列表查找到任 ...

  4. Spring Boot Scheduled定时任务特性

    SpringBoot中的Scheduled定时任务是Spring Boot中非常常用的特性,用来执行一些比如日切或者日终对账这种定时任务 下面说说使用时要注意的Scheduled的几个特性 Sched ...

  5. Service Mesh架构的持续演进 单体模块化 SOA 微服务 Service Mesh

    架构不止-严选Service Mesh架构的持续演进 网易严选 王育松 严选技术团队 2019-11-25 前言同严选的业务一样,在下层承载它的IT系统架构一样要生存.呼吸.增长和发展,否则过时的.僵 ...

  6. 房产基于Swoole的PHP RPC框架设计

    房产基于Swoole的PHP RPC框架设计 https://mp.weixin.qq.com/s/XSrKEQ-0q4DvjOGTIwYYzg

  7. 不占用额外内存空间能否做到 将图像旋转90度 N &#215; N矩阵表示的图像,其中每个像素的大小为4字节

    给定一幅由N × N矩阵表示的图像,其中每个像素的大小为4字节,编写一种方法,将图像旋转90度. 不占用额外内存空间能否做到? 示例 1: 给定 matrix = [ [1,2,3], [4,5,6] ...

  8.  Go is more about software engineering than programming language research.

    https://talks.golang.org/2012/splash.article Go at Google: Language Design in the Service of Softwar ...

  9. Buffer Data RDMA 零拷贝 直接内存访问

    waylau/netty-4-user-guide: Chinese translation of Netty 4.x User Guide. 中文翻译<Netty 4.x 用户指南> h ...

  10. .params和query的区别

    用法:query要用path来引入,params要用name来引入,接收参数都是类似的,分别是this.$route.query.name和this.$route.params.name.url地址显 ...