CodeForces 755APolandBall and Hypothesis
来源:互联网 发布:长江证券mac版本 编辑:程序博客网 时间:2024/06/05 09:54
题目链接:http://codeforces.com/contest/755/problem/A
题意:给你一个整数n,让你求一个m,使得n*m+1不是素数
解析:由于题目有说明,所以可以直接暴力的把m求出来,但是有更简单的办法,完全平方式是n*n+2*n+1,所以直接输出n+2就好了,但是他说了答案不能超过1e3,所以要稍微处理一下
#include <bits/stdc++.h>using namespace std;const int maxn = 3e5+100;const int inf = 0x7fffffff;int main(void){ int n; scanf("%d",&n); if(n+2>1e3) printf("%d\n",n-2); else printf("%d\n",n+2); return 0;}
#include <bits/stdc++.h>using namespace std;const int maxn = 3e5+100;const int inf = 0x7fffffff;bool is_prime(int n){ if(n<2) return false; for(int i=2;i*i<=n;i++) { if(n%i==0) return false; } return true;}int main(void){ int n; scanf("%d",&n); if(n%2) puts("5"); else { for(int i=1;i<=1e3;i++) { if(!is_prime(i*n+1)) { printf("%d\n",i); break; } } } return 0;}
0 0
- CodeForces 755APolandBall and Hypothesis
- 【codeforces 755A】PolandBall and Hypothesis
- 755A PolandBall and Hypothesis
- Codefoeces 755A-PolandBall and Hypothesis
- A. PolandBall and Hypothesis
- 文章标题 CoderForces 755A : PolandBall and Hypothesis(水)
- codefors755A. PolandBall and Hypothesis(打表+二分)
- Infinite size of Hypothesis set and growth funciton
- CodeForces 755CPolandBall and Forest
- Distributional hypothesis
- Hypothesis Testing
- null hypothesis
- 8VC Venture Cup 2017 - Elimination Round A. PolandBall and Hypothesis【水题】
- 【codeforces 755B】PolandBall and Game
- 【codeforces 755C】PolandBall and Forest
- 【codeforces 755D】PolandBall and Polygon
- codeforces-755-B PolandBall and Game
- Codeforces 755-B. PolandBall and Game(贪心)
- LeetCode:75. Sort Colors
- 滴滴面试总结
- 1111. Online Map (30)
- TCP可靠的数据传输
- 用thymeleaf用标签给页面select下拉框赋值
- CodeForces 755APolandBall and Hypothesis
- properties 的操作和运用实例
- TCP四次挥手
- 无法打开模块文件“C:\Users\Cathy\AppData\Local\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.vb”
- TCP滑动窗口协议
- 中文按双字处理的案例
- java学习笔记--二进制基础
- Android数据存储五种方式总结
- 选择排序(包含堆排序)