hdu 4715 Difference Between Primes

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4715 

Difference Between Primes

Description

All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the difference of two primes. To validate this conjecture, you are asked to write a program.

Input

The first line of input is a number nidentified the count of test cases(n<10^5). There is a even number xat the next nlines. The absolute value of xis not greater than 10^6.

Output

For each number xtested, outputstwo primes aand bat one line separatedwith one space where a-b=x. If more than one group can meet it, output the minimum group. If no primes can satisfy it, output 'FAIL'.

Sample Input

3
6
10
20

Sample Output

11 5
13 3
23 3

素数筛选+二分判断。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::map;
using std::min;
using std::find;
using std::pair;
using std::vector;
using std::multimap;
using std::lower_bound;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 1000000;
const int INF = 0x3f3f3f3f;
int tot, prime[N + 10];
bool is_prime[N + 10];
inline void init() {
    tot = 0;
    rep(i, N) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= N; i++) {
        if(is_prime[i]) {
            prime[tot++] = i;
            for(int j = 2 * i; j <= N; j += i) is_prime[j] = false;
        }
    }
}
void solve(int x) {
    rep(i, tot) {
        int p = lower_bound(prime, prime + tot, prime[i] + x) - prime;
        if(prime[i] + x == prime[p]) {
            printf("%d %d\n", prime[p], prime[i]);
            return;
        }
    }
    puts("FAIL");
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w+", stdout);
#endif
    init();
    int t, n;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        solve(n);
    }
    return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4792991.html

大模型系列——Ollama-OCR 简明教程 Llama 3.2-Vision 是一个多模态大型语言模型,有 11B 和 90B 两种大小,能够处理文本和图像输入以生成文本输出。该模型在视觉识别、图像推理、图像描述和回答与图像相关的问题方面表现出色,在多个行业基准测试中优于现有的开源和闭源多模态模型。在本文中,我将介绍如何调用由 Ollama 运行的 Llama 3.2-Vision 11B 建模服务并使用实现图像文本识别 (OCR) 功能。 阅读详情

相关推荐

Pinocchio 安装教程|机器人学的必备库

安装pinocchio,不要安装pip3 install pinocchio!

darcsdn 1671

HDU-4715 Difference Between Primes(线性筛法)

Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4158Accepted Submission(s): 1194 Problem Description All you ...

weixin_34232363的博客 153

晟矽微MC32F7361定时器的使用案例说明

110所以TIMER0所用的频率是FCPU的1/64,也就是8/64MHZ. 为1/8MHZ。//io口下拉电阻 1:enable 0:disablea。//io口上拉电阻 1:enable 0:disable。//io口下拉电阻 1:enable 0:disable。//io口上拉电阻 1:enable 0:disable。//io口下拉电阻 1:enable 0:disable。//io口上拉电阻 1:enable 0:disable。

liyanfei123456的博客 1140

hdu4715 Difference Between Primes

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715 #include #include #define MAXN 1010000 #define SIZE 1010002 int prime[SIZE],valid[SIZE]; void getPrime()//素数筛选O(N) { int i,j,

不可不戒 799

VBA中如何使用Edge内核Browser?

在微软宣布停止对IE的支持后,许多使用VBA中Web Browser的用户遇到了困境,因为Web Browser使用的IE内核。然而微软并没有给出支持Edge的新版Web Browser,网上许多第三方的库也不够完善。经过调研,libEdge可以较好的和VBA集成,实现在Excel中打开Browser,甚至能够通过执行js代码,获取web页面的信息。项目需要WebView2Loader.dll和LibEdge.dll两个库,区分x86和x64版本。

金木AI 2407

FPGA可重构技术

介绍FPGA 可重构技术的实现方法,包括全局重构和部分重构

航天领域资深码农,型号经验丰富,一线干货分享 1992

hdu 4715 Difference Between Primes 筛法

hdu 4715 Difference Between Primes 筛法 All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the differen

klc的博客 658

PYNQ开发板使用-使用DMA进行数据搬移(Simple DMA transfer 模式)

该篇是学习使用PYNQ开发板,实际上是对ZYNQ PL端AXI_CDMA 核的应用。实验步骤参照官网的教程,一步一步地做,但是由于在硬件资源布置方面与官方教程稍有出入,所以在SDK的源码里也进行了修改。 AXI_CDMA特性: 如果是使用ZYNQ 7系列芯片(可能其他Xilinx也是通用的),xilinx的AXI_CDMA 核有两种传输模式:轮询(poll)和中断(...

YGLeeeon的博客 3525

HDU 4715 Difference Between Primes

Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even

只为给你最好的的明天。 661

[从零开始学习FPGA编程-18]:快速入门篇 - 操作步骤2-6- VerilogHDL时序电路语法分析(以计数器为例)

目录前言:第1章 功能模块代码:counter.v第2章 驱动代码:tcounter.v前文以及阐述了VerilogHDL基本语法,本文将以modelsim自带的计数器程序来解读VerilogHDL的语法。代码路径:

文火冰糖(王文兵)的博客 7万+

20 Embedding 与向量检索:语义为什么能变成距离

Embedding 是 RAG 语义检索的数学基础。本文用工程视角讲清文本如何变成向量,为什么语义相近会表现为距离相近,Top-K 检索如何工作,以及在模型选择、同模型约束、精确匹配和召回评估上的常见坑。

老于的笔记的专栏 6209

hdu4715Difference Between Primes

Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 894    Accepted Submission(s): 290 Problem Description Al

Min_lala的专栏 1048

ZYNQ PS-PL数据交互方式总结

一,中断 二,IO方式:MIO EMIO GPIO 三,BRAM或FIFO或EMIF (1)通过BRAM实现PL/PS之间交互 PS 的配置如下图所示。使能 M_AXI_GP0 口,将 FCLK_CLK0 设为 100MHz,使能 PL 至 PS 的中断。 AXI BRAM Controller IP 核连接 PS 的 M_AXI_GP0 口和 BRAM,完成 AXI 接口至 BRAM 接口的转换。 添加BRAM,将BRAM设置为双口RAM,将PORTA与AXI B...

wangjie36的博客 1万+

HDU 4715 Difference Between Primes && 2013 ACM/ICPC Asia Regional Online —— Warmup

#include #include #include #include using namespace std; #define Pn 9592 int prime[Pn]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,

九野的博客 6318

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

hdu 4715 Difference Between Primes

Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even in

HJ 876

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

hdu(4715) Difference Between Primes

题意:一个数看是否能用两个素数之差来表示; 把素数存在一个数组里;查遍所有素数;   #include"stdio.h" #include"string.h" #include"math.h" #define N 1050000 int map[N]; int prime[N]; int main() {  memset(prime,0,sizeof(prime));  i

飞雪---晨 655

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDU 4715 Difference Between Primes 半个打表题。。

Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 402    Accepted Submission(s): 110 Problem Description Al

I will Do iT @ hlyblog.net 1597

hdu 4715 Difference Between Primes(stl)

题目连接:4715 Difference Between Primes 题目大意:给出n个x, 0 解题思路:将2 ~ 10^6 + 10以内的素数表求出, 对应的去匹配pri[i] + x是否为素数, 这里我借用了stl里面的set. #include #include #include #include using namespace std; con

不慌不忙、不急不躁 1206

hdu 4715 Difference Between Primes (打表 枚举)

Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 528    Accepted Submission(s): 150 Problem Description

To be what you what to be! 1666
上一篇: hdu 4707 Pet
下一篇: hdu 4857 逃生
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值