What is the hypothesis related to PolandBall in CodeForces 755A problem?

更新于
2026-07-28 04:53:34
20阅读来源:SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计384个文字,预计阅读时间需要2分钟。

What is the hypothesis related to PolandBall in CodeForces 755A problem?

题目链接:http://codeforces.com/contest/755/problem/A题目:给你一个整数n,让你找到一个m,使得n+m+1不是素数解析:由于题目已经说明了,可以直接暴力求解m,但更简单的方法是直接尝试m=1,因为如果n+2是素数,那么n+1就是合数,反之亦然。

What is the hypothesis related to PolandBall in CodeForces 755A problem?


题目链接:​​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;
}


本文共计384个文字,预计阅读时间需要2分钟。

What is the hypothesis related to PolandBall in CodeForces 755A problem?

题目链接:http://codeforces.com/contest/755/problem/A题目:给你一个整数n,让你找到一个m,使得n+m+1不是素数解析:由于题目已经说明了,可以直接暴力求解m,但更简单的方法是直接尝试m=1,因为如果n+2是素数,那么n+1就是合数,反之亦然。

What is the hypothesis related to PolandBall in CodeForces 755A problem?


题目链接:​​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;
}