题解 CF755A 【PolandBall and Hypothesis】
直接从1开始枚举不就行了...
思路如下:
1.先定义一个判断是不是质数的函数
int pd(int n)
{
if(n==1)return true;
if(n==2)return false;
for(int i=2;i*i<=n;i++)
if(n%i==0)return true;
return false;
}
2.从1开始枚举,可以直接使用
for(int i=1;;i++)
进行枚举
3.判断i是否满足要求,调用函数,如果满足,就直接输出i并且break或return 0
for(int i=1;;i++)
{
if(pd(n*i+1))
{
cout<<i;
return 0;
}
}
#include <bits/stdc++.h>
using namespace std;
int pd(int n)
{
if(n==1)return true;//特判
if(n==2)return false;
for(int i=2;i*i<=n;i++)
if(n%i==0)return true;
return false;
}//判断是不是素数
int main()
{
long long n;
cin>>n;
for(int i=1;;i++)
{
if(pd(n*i+1))//按照题目里的公式判断
{
cout<<i;
return 0;//找到了,return
}
}//枚举
return 0;
}
题解 CF755A 【PolandBall and Hypothesis】的更多相关文章
- 【codeforces 755A】PolandBall and Hypothesis
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 题解 【Codeforces755A】 PolandBall and Hypothesis
我们可以发现,当n>2时,n·(n-2)+1=(n-1)·(n-1),因此,输出n-2即可. 如果n<=2,我们可以发现: 当n=2时,2·4+1=9不是质数,输出4即可: 当n=1时,1 ...
- 题解-CF755G PolandBall and Many Other Balls
题面 CF755G PolandBall and Many Other Balls 给定 \(n\) 和 \(m\).有一排 \(n\) 个球,求对于每个 \(1\le k\le m\),选出 \(k ...
- Codeforces 755A:PolandBall and Hypothesis(暴力)
http://codeforces.com/problemset/problem/755/A 题意:给出一个n,让你找一个m使得n*m+1不是素数. 思路:暴力枚举m判断即可. #include &l ...
- 解题报告8VC Venture Cup 2017 - Elimination Round
题目链接:http://codeforces.com/contest/755 本蒟蒻做了半天只会做前两道题.. A. PolandBall and Hypothesis 题意:给出n,让你找出一个m, ...
- 大素数判断(miller-Rabin测试)
题目:PolandBall and Hypothesis A. PolandBall and Hypothesis time limit per test 2 seconds memory limit ...
- 某5道CF水题
1.PolandBall and Hypothesis 题面在这里! 大意就是让你找一个m使得n*m+1是一个合数. 首先对于1和2可以特判,是1输出3,是2输出4. 然后对于其他所有的n,我们都可以 ...
- CF755G PolandBall and Many Other Balls 题解
从神 Karry 的题单过来的,然后自己瞎 yy 了一个方法,看题解区里没有,便来写一个题解 一个常数和复杂度都很大的题解 令 \(dp_{i,j}\) 为 在 \(i\) 个球中选 \(j\) 组的 ...
- CF755C PolandBall and Forest 题解
Content 给定无向图的 \(n\) 个点的父亲节点,求无向图的联通块个数. 数据范围:\(1\leqslant n\leqslant 10^4\). Solution 并查集模板题. 我们将在当 ...
随机推荐
- PMP--2. 项目启动前准备工作
####################################################### 概述:在第一章节的1.1-1.7中基本都是介绍的<PMBOK>的理论概念以及 ...
- KINDLE 小说下载--超级书库
网址:https://shuayouxi.cn/
- SpringBoot支持SpringData es
ElasticSearch CRUD 1.springboot springData es spring data 是spring对数据访问抽象.这些数据可以放入db,index,nosql等包含以下 ...
- 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发 阅读导航 本文背景 代码 ...
- MySQL安装图解及调试
MySQL 5.7安装图解 注意:请确认系统是否已安装Microsoft Visual C++2013 Redistributable基本运行库,开始>控制面板>卸载程序中查看,如图所示: ...
- Nginx架构分析(20200202)
Nginx模块化 Nginx基于模块化设计,每个模块是一个功能实现,分布式开发,团队协作 核心模块.标准HTTP模块.可选HTTP模块.邮件模块.第三方模块 编译后的源码目录objs/ngx_modu ...
- P5788 【模板】单调栈
---------------- 链接:Miku ---------------- 单调栈模板终于不是一堆蓝题了!!!!!!!!!!!! 单调栈,就是单调的栈,栈内元素都是单调的. 题目要求我们求出来 ...
- Expert C Programming(C专家编程) 读书笔记
目录 几个比较奇葩的指针赋值 int (* fun())() int (* foo())[] int (*foo[])() const 关键词的意义是什么? char const (*next )() ...
- 【45】谷歌 Inception 网络简介Inception(1)
谷歌 Inception 网络简介(Inception network motivation) 构建卷积层时,你要决定过滤器的大小究竟是1×1,3×3还是5×5,或者要不要添加池化层.而Incepti ...
- formateDate
function formateDate(fmt, date) { let _this = new Date(date) let o = { "M+": _this.getMont ...