Codeforces Round #696 (Div. 2) B. Different Divisors

B. Different Divisors#

link

题意#

T 组数据,每组数据给定一个数字 d ,求出一个最小的数字 x 满足 x 至少有 4 个因数,并且任意两个因数之差大于等于 d

数据范围#

1T3000,1d10000

SOLUTION#

由于至少有 4 个因数,并且任意两个因数之差大于等于 d容易得出因数越多越劣。因此考虑枚举 x 除了 1,x 之外 的两个因数 a,b,由于 x 只有 4 个因数,因此 a,b 都是质数,并且 a1+d,ba+d,考虑预处理质因数,二分求解 a,b 即可。

CODE#

点击查看代码
/* Generated by powerful Codeforces Tool
 * Author: SmartNanfeng
 * Time: 2022-09-08 22:35:01
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#ifdef LOCAL
#include <debugger>
#else
#define debug(...) 42
#endif

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

constexpr int N = 3E4 + 10;

int primes[N], cnt;
bool st[N];

void init() {
  int n = N - 1;
  for (int i = 2; i <= n; i ++ ) {
    if (!st[i]) primes[cnt ++ ] = i;
    for (int j = 0; primes[j] <= n / i; j ++ ) {
      st[primes[j] * i] = true;
      if (i % primes[j] == 0) {
        break;
      }
    }
  }
}

void solve2() {
  int d; cin >> d;
  int idx = lower_bound(primes, primes + cnt, d + 1) - primes;
  int x = primes[idx];
  idx = lower_bound(primes, primes + cnt, x + d) - primes;
  int y = primes[idx];
  cout << x * y << "\n";
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  init();
  int T = 1; cin >> T;
  while (T --) solve2();
  return 0;
}

/*
 *
 *  ┏┓   ┏┓+ +
 * ┏┛┻━━━┛┻┓ + +
 * ┃       ┃
 * ┃   ━   ┃ ++ + + +
 *  ████━████+
 *  ◥██◤ ◥██◤ +
 * ┃   ┻   ┃
 * ┃       ┃ + +
 * ┗━┓   ┏━┛
 *   ┃   ┃ + + + +Code is far away from  
 *   ┃   ┃ + bug with the animal protecting
 *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
 *   ┃        ┣┓
 *    ┃        ┏┛
 *     ┗┓┓┏━┳┓┏┛ + + + +
 *    ┃┫┫ ┃┫┫
 *    ┗┻┛ ┗┻┛+ + + +
 */

posted @   ccz9729  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示
主题色彩