直接从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】的更多相关文章

  1. 【codeforces 755A】PolandBall and Hypothesis

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 题解 【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 ...

  3. 题解-CF755G PolandBall and Many Other Balls

    题面 CF755G PolandBall and Many Other Balls 给定 \(n\) 和 \(m\).有一排 \(n\) 个球,求对于每个 \(1\le k\le m\),选出 \(k ...

  4. Codeforces 755A:PolandBall and Hypothesis(暴力)

    http://codeforces.com/problemset/problem/755/A 题意:给出一个n,让你找一个m使得n*m+1不是素数. 思路:暴力枚举m判断即可. #include &l ...

  5. 解题报告8VC Venture Cup 2017 - Elimination Round

    题目链接:http://codeforces.com/contest/755 本蒟蒻做了半天只会做前两道题.. A. PolandBall and Hypothesis 题意:给出n,让你找出一个m, ...

  6. 大素数判断(miller-Rabin测试)

    题目:PolandBall and Hypothesis A. PolandBall and Hypothesis time limit per test 2 seconds memory limit ...

  7. 某5道CF水题

    1.PolandBall and Hypothesis 题面在这里! 大意就是让你找一个m使得n*m+1是一个合数. 首先对于1和2可以特判,是1输出3,是2输出4. 然后对于其他所有的n,我们都可以 ...

  8. CF755G PolandBall and Many Other Balls 题解

    从神 Karry 的题单过来的,然后自己瞎 yy 了一个方法,看题解区里没有,便来写一个题解 一个常数和复杂度都很大的题解 令 \(dp_{i,j}\) 为 在 \(i\) 个球中选 \(j\) 组的 ...

  9. CF755C PolandBall and Forest 题解

    Content 给定无向图的 \(n\) 个点的父亲节点,求无向图的联通块个数. 数据范围:\(1\leqslant n\leqslant 10^4\). Solution 并查集模板题. 我们将在当 ...

随机推荐

  1. opencv —— convexHull 寻找并绘制凸包

    凸包的定义: 包含点集 S 所有点的最小凸多边形称为凸包. 凸包绘制原理:Graham 扫描法 首先选择 y 方向上最低的点作为起始点 p0. 然后以 p0 为原点,建立极坐标系,做逆时针极坐标扫描, ...

  2. Mac保留Python2安装Python3(Anaconda3)

    作为开发人员,通常是离不开Python环境的(即便你是Java-er.Js-er.Php-er .etc.). 为何要保留Python2 Mac大多自带了python 2的环境,但是Python2在2 ...

  3. Python 获取本地主机信息

    import wmi c = wmi.WMI() for sys in c.Win32_OperatingSystem(): #系统信息 print(sys.Caption) #系统版本号 print ...

  4. 两张图搞清楚Eclipse上的Web项目目录

    从MyEclipse转到Eclipse起初有点不习惯eclipse的目录结构,顺手一查看到的文章帮助很大,转载一下: 原文链接:https://www.jianshu.com/p/91050dfcbe ...

  5. LeetCode 面试题 02.03. 删除中间节点

    题目链接:https://leetcode-cn.com/problems/delete-middle-node-lcci/ 实现一种算法,删除单向链表中间的某个节点(除了第一个和最后一个节点,不一定 ...

  6. app简单压力测试

    step1:手机开发者选项中,将USB调试选上 step2:确认手机和电脑已经连接成功:adb devices step3:安装测试app:adb install package.apk (1)cd命 ...

  7. cf1037E

    题解:考虑逆序处理询问,用一个set来维护能去的人,每次减少边的时候,维护一下这个set就可以,具体看代码 int main(){ int n, m, k; cin >> n >&g ...

  8. lombok版本过低报错

    调试报错Error:java: java.lang.ExceptionInInitializerError  com.sun.tools.javac.code.TypeTags JAVA12调整原有项 ...

  9. laravel orWhere

    场景描述 需要根据商品分类.商品名称和条形码这三个查询条件去取出结果集,这三者的关系是:商品分类 and (商品名称 or 条形码) 错误尝试 第一次写出来的代码是这样的: $goodsModel = ...

  10. Python、Django、Celery中文文档分享

    1.Python:链接:https://pan.baidu.com/s/12uzxbI-nMkpF7aMa966bTQ 密码:i1x9 2.Django:链接:https://pan.baidu.co ...