Codeforces Panoramix's Prediction
// Accepted
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define N 100
#define sf scanf
#define pf printf
using namespace std;
int stats[(N/2)+1],arr[N],len=1;
void prime ()
{
int i,j,qrt;
for (i=2;i<=N>>1;i++)
{
stats[i] = 0;
}
qrt = int (sqrt(double (N)));
for (i=3;i<=qrt;i+=2)
{
if (stats[i>>1] == 0) {
for (j=i*i;j<=N;j+=i+i)
{
stats[j>>1] = 1;
}
}
}
arr[0] = 2;
for (i=3;i<=N;i+=2)
{
if (stats[i>>1] == 0)
{
arr[len] = i;
len++;
}
}
}
int main()
{
prime();
/*for (int i=0;i<len;i++)
{
printf("%d ",arr[i]);
}*/
int n,m,d;
bool f = false;
cin >> n >> m;
for (int i=0;i<len;i++)
{
if (m == arr[i])
{
d = i;
if (arr[d-1] == n)
{
f = true;
break;
}
}
}
if (f)
{
printf("YES");
}
else
{
printf("NO");
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define N 100
#define sf scanf
#define pf printf
using namespace std;
int stats[(N/2)+1],arr[N],len=1;
void prime ()
{
int i,j,qrt;
for (i=2;i<=N>>1;i++)
{
stats[i] = 0;
}
qrt = int (sqrt(double (N)));
for (i=3;i<=qrt;i+=2)
{
if (stats[i>>1] == 0) {
for (j=i*i;j<=N;j+=i+i)
{
stats[j>>1] = 1;
}
}
}
arr[0] = 2;
for (i=3;i<=N;i+=2)
{
if (stats[i>>1] == 0)
{
arr[len] = i;
len++;
}
}
}
int main()
{
prime();
/*for (int i=0;i<len;i++)
{
printf("%d ",arr[i]);
}*/
int n,m,d;
bool f = false;
cin >> n >> m;
for (int i=0;i<len;i++)
{
if (m == arr[i])
{
d = i;
if (arr[d-1] == n)
{
f = true;
break;
}
}
}
if (f)
{
printf("YES");
}
else
{
printf("NO");
}
return 0;
}
Comments
Post a Comment