CF1474-B. Different Divisors
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的更多相关文章
- 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 ...
- 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 ...
- Divisors
计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...
- Xenia and Divisors
Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hihocoder1187 Divisors
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- 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 ...
- UVa 294 (因数的个数) Divisors
题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...
- hdu4432 Sum of divisors(数论)
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- CS远控
Cobaltstrike 一.基础使用 ./teamserver 192.168.43.224 123456 启动服务器端 在windows下的链接 双击bat文件即可 在linux下 ./start ...
- [APUE] 文件 I/O
文件操作相关 API:open, read, write, lseek, close. 多进程共享文件的相关 API:dup, dup2, fcntl, sync, fsync, ioctl. 文件操 ...
- layui表格前端格式化时间戳字段
layui.use(['util','table'], function(){ var table = layui.table; var util = layui.util; //... ...
- 干电池升压3.3V的电源芯片
PW5100适用于一节干电池升压到3.3V,两节干电池升压3.3V的升压电路,PW5100干电池升压IC. 干电池1.5V和两节干电池3V升压到3.3V的测试数据 两节干电池输出500MA测试: PW ...
- Java流程控制与Scanner类的使用
Java流程控制与Scanner类的使用 Scanner类 Scanner类可以使程序接受键盘输入,实现人机交互 一个完整的Scanner的使用例子: //创建一个扫描器对象,用于接收键盘数据 Sca ...
- 02_Python基础
2.1 第一条编程语句 print("Hello, Python!") print("To be, or not to be, it's a question." ...
- 【故障公告】K8s CofigMap 挂载问题引发网站故障
今天凌晨我们用阿里云服务器自建的 kubernetes 集群出现突发异常情况,博客站点(blog-web)与博客 web api(blog-api)的 pod 无法正常启动(CrashLoopBack ...
- 使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理
使用Linux服务器来通过网络安装和激活Windows 7 -- 一些基本原理 https://www.pufengdu.org/blog/?p=372
- springboot配置rabbitmq
一.消息生成者 1.1消息生成者配置 1.2 消息发送端代码 1.3 创建交换机,队列,并建立关系 二.消费者 2.1消费者 三.限流配置 3.1配置文件 #在单个请求中处理的消息个数,他应该大于等于 ...
- 大数据开发-Spark-拷问灵魂的5个问题
1.Spark计算依赖内存,如果目前只有10g内存,但是需要将500G的文件排序并输出,需要如何操作? ①.把磁盘上的500G数据分割为100块(chunks),每份5GB.(注意,要留一些系统空间! ...