CF1269A Equation
CF1269A Equation
题意
要找两个合数,使他们两个的差为\(n\),\(n\)为题目给出的数
思路
我们可以枚举减数\(now\),判断一下是不是质数,如果是质数就让\(now++\),然后用一个数\(tot\)记录被减数,也就是\(now\)加\(n\),判断\(tot\)是不是质数,如果是质数再让\(now++\),如果不是质数我们就找到了答案,因为我们已经保证了\(now\)为合数,所以就可以直接跳出循环输出答案啦~
因为数据范围并不大,所以我们可以直接判断一个数是不是质数,如下
//判断是否为质数,是质数返回1,否则返回0
bool check(int wh) {
if(wh <= 1) return 0;
if(wh == 2) return 1;
for(int i = 2; i * i <= wh; i++) if(wh % i == 0) return 0;
return 1;
}
代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int A = 5e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline int read() {
char c = getchar(); int x = 0, f = 1;
for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return x * f;
}
//判断是否为质数,是质数返回1,否则返回0
bool check(int wh) {
if(wh <= 1) return 0; if(wh == 2) return 1;
for(int i = 2; i * i <= wh; i++) if(wh % i == 0) return 0;
return 1;
}
int main() {
int n = read(), now = 2, tot;
while(1) {
if(check(now)) now++;
//判断now是否为质数,如果是质数就++,否则继续判断tot的值
else {
tot = now + n;
if(check(tot)) now++;
//判断tot是否为质数,如果不是质数就可以跳出输出答案了
else break;
}
}
return cout << tot << " " << now << '\n', 0;
}
CF1269A Equation的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分
Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- Xcode真机运行报错iPhone has denied the launch request
1.打开钥匙串 ->Apple Worldwide Developer Relations Certification Authority ->双击 并点击信任->选择使用系统默认2 ...
- Python3操作MySQL基于PyMySQL封装的类
Python3操作MySQL基于PyMySQL封装的类 在未使用操作数据库的框架开发项目的时候,我们需要自己处理数据库连接问题,今天在做一个Python的演示项目,写一个操作MySQL数据库的类, ...
- 017.Kubernetes二进制部署检查集群
一 验证集群功能 1.1 检查节点状态 [root@k8smaster01 ~]# kubectl get nodes 1.2 创建测试文件 [root@k8smaster01 ~]# cd /opt ...
- Python+Unittest+Requests+PyMysql+HTMLReport 接口自动化框架
整体框架使用的是:Python+Unittest+Requests+PyMysql+HTMLReport 多线程并发模式 主要依赖模块 Unittest.Requests.PyMysql.HTMLR ...
- 【bzoj5339】[TJOI2018]教科书般的亵渎(拉格朗日插值/第二类斯特林数)
传送门 题意: 一开始有很多怪兽,每个怪兽的血量在\(1\)到\(n\)之间且各不相同,\(n\leq 10^{13}\). 然后有\(m\)种没有出现的血量,\(m\leq 50\). 现在有个人可 ...
- poj 3061 Subsequence 二分 前缀和 双指针
地址 http://poj.org/problem?id=3061 解法1 使用双指针 由于序列是连续正数 使用l r 表示选择的子序列的起始 每当和小于要求的时候 我们向右侧扩展 增大序列和 每当和 ...
- alter对话框处理:
from selenium import webdriverd = webdriver.Firefox()d.get('file://C:\\我的代码\\selenium自动化测试\\alter.ht ...
- 一些常用的 redis 的操作配置(对String、hash)
import java.util.List; import java.util.Map; import org.apache.logging.log4j.LogManager; import org. ...
- nginx如何实现负载均衡以及实现方式
什么是ngnix? Nginx是一个http服务器.是一个使用c语言开发的高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.nginx能够支撑5万并发链接,并且cpu ...
- numpy-np.ceil,np.floor,np.expand_dims方法
np.ceil(多维数组):对多维数组的各个数向上取整 np.floor(多维数组):对多维数组的各个数向下取整 np.expand_dims(x,axis = 0):在x的第一维度上插入一个维度,a ...