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) ...
随机推荐
- 【EXPDP/IMPDP】数据泵导入导出遇到目录没有权限问题
当执行数据泵导出的时候,报了如下错误: ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: ...
- spring boot项目问题汇总
spring遇到的问题汇总 有关日志的打印和日志如何使用 在实际项目中,我们的程序都是运行在linux上,有错误时也不能在本地的控制台上直观看到,所有合理打印日志对于程序员迅速定位到错误. 打印日志时 ...
- 基于HBuilderX+UniApp+ColorUi+UniCloud 优宝库 开发实战(一)
1. 优宝库介绍 优宝库是基于阿里妈妈.淘宝联盟 淘宝商品Api,前端使用HBuilderX + UniApp + ColorUi,后端采用UniClound 精选淘宝商品进行推荐的App程序.下 ...
- 导出exe的经验
安装pyinstaller 首先要找到scripts的绝对路径(主要是找到scripts就行了 先是安装C:\Users\96290\AppData\Local\Programs\Python\Pyt ...
- ORB-SLAM2-tracking线程
tracking线程 Tracking线程的主要工作是从图像中提取ORB特征,根据上一帧进行姿态估计或者进行通过全局重定位初始化位姿,然后跟踪已经重建的局部地图,优化位姿,再根据一些规则确定新的关键帧 ...
- 面试必问:如何实现Redis分布式锁
摘要:今天我们来聊聊分布式锁这块知识,具体的来看看Redis分布式锁的实现原理. 一.写在前面 现在面试,一般都会聊聊分布式系统这块的东西.通常面试官都会从服务框架(Spring Cloud.Dubb ...
- Samba共享工具安装
Samba 是一种在局域网上共享文件的一种通信协议,它为局域网内的不同计算机之间提供文件的共享服务. (1)下载并安装 Samba 工具. 确定 Ubuntu 已连接到互联网, 执行如下命令下载 Sa ...
- Spring-01-事务
Spring事务机制 spring事务机制最重要的两个配置项,隔离级别和传播特性. 1. 隔离级别 隔离级别针对高并发问题导致的数据库丢失更新问题 1.1 数据库的4大基本特征 原子性(Atomic) ...
- 一文带你看遍 JDK9~14 的重要新特性!
Java9 发布于 2017 年 9 月 21 日 .作为 Java8 之后 3 年半才发布的新版本,Java 9 带 来了很多重大的变化其中最重要的改动是 Java 平台模块系统的引入,其他还有诸如 ...
- LOJ10019生日蛋糕
Mr.W 要制作一个体积为 N*π 的 M 层生日蛋糕,每层都是一个圆柱体. 设从下往上数第 i 蛋糕是半径为 R_i,高度为 H_i 的圆柱.当 i<M 时,要求 R_i>R_{i+1} ...