【codeforces 755A】PolandBall and Hypothesis
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: “There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number”.
Unfortunately, PolandBall is not experienced yet and doesn’t know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.
Input
The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall’s hypothesis.
Output
Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.
Examples
input
3
output
1
input
4
output
2
Note
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.
【题目链接】:http://codeforces.com/contest/755/problem/A
【题解】
枚举m从1..1000就好;
(special way 注意到当m=n+2的时候,n*m+1=(n+1)^2,而当m=n-2的时候,n*m+1=(n-1)^2,所以对n分类讨论一下就可以了.)
代码给的是枚举的.
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 110;
int n;
bool is(int k)
{
int len = sqrt(k);
rep1(j,2,len)
if (k%j==0)
{
return false;
}
return true;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(m,1,1000)
{
int k = n*m+1;
//cout << k <<endl;
if (!is(k))
{
printf("%d\n",m);
return 0;
}
}
return 0;
}
【codeforces 755A】PolandBall and Hypothesis的更多相关文章
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755C】PolandBall and Forest
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 755F】PolandBall and Gifts
[题目链接]:http://codeforces.com/contest/755/problem/F [题意] n个人; 计划是每个人都拿一个礼物来送给一个除了自己之外的人; 且如果一个人没有送出礼物 ...
- 【codeforces 755E】PolandBall and White-Red graph
[题目链接]:http://codeforces.com/contest/755/problem/E [题意] 给你n个节点; 让你在这些点之间接若干条边;构成原图(要求n个节点都联通) 然后分别求出 ...
- Codeforces 755A:PolandBall and Hypothesis(暴力)
http://codeforces.com/problemset/problem/755/A 题意:给出一个n,让你找一个m使得n*m+1不是素数. 思路:暴力枚举m判断即可. #include &l ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...
- app 自动化测试 Appium+Java可以运行的代码
地址:http://www.cnblogs.com/sunny-sl/p/6520465.html
- HSV颜色模型
HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色空间, 也称六角锥体模型(Hexcone Model). 注意的是OpenC ...
- 【Codeforces Round #432 (Div. 2) A】 Arpa and a research in Mexican wave
[链接]h在这里写链接 [题意] 在这里写题意 [题解] t<=k,输出t t>=n,输出k-t+n 其他情况都是k [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #in ...
- Android开发人员应该知道的Kotlin
本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2016/01/kotlin-android Android开发人员在语言限制方面面临着 ...
- Android 网络图片Url 转 Bitmap
注意:该方法必须要在子线程中调用,因为涉及网络请求 public Bitmap getBitmap(String url) { Bitmap bm = null; try { URL iconUrl ...
- OFFICE2013 打开两个word文档卡死的解决办法
这几天Office打开一个word好好的,两个就直接卡死了,百度了一下: 原文地址: http://hi.baidu.com/pjhero/item/ca326e3dcfebebb9623aff6e ...
- 低成本开始互联网创业:探讨域名、服务器、CDN、邮箱等节流之道
互联网创业一直是个热门话题,对这个问题我也有不断的思考. 今天,探讨下如何低成本开始互联网创业. 背景 愿意冒险去创业的同志,大多是"屌丝"而非"高富帅",大多 ...
- Android OnGestureListener用法 识别用户手势 左右滑动
Android可以识别用户的手势(即用户用手指滑动的方向),通过用户不同的手势,从而做出不同的处理 需要使用OnGestureListener 比如说看电子书的时候翻页,或者要滑动一些其他内容 直接上 ...
- malloc和realloc
malloc函数: extern void *malloc(unsigned int num_bytes); malloc 向系统申请分配指定size个字节的内存空间. 如果分配成功则返回指向被分配内 ...