80A - Panoramix's Prediction - CodeForces Solution


brute force *800

Please click on ads to support us..

Python Code:

prime = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227]
num,num2 = list(map(int,input().split()))
for i in range(50):
    if prime[i] == num:
        break
if prime[i+1] == num2:
    print("YES")
else:
    print("NO")
    

C++ Code:

// Problem: A. Panoramix's Prediction
// Contest: Codeforces - Codeforces Beta Round #69 (Div. 2 Only)
// URL: https://codeforces.com/problemset/problem/80/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)


#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mod 1e9 + 7
// #define for(a, c) for (int(a) = 0; (a) < (c); (a)++)
// #define forl(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
// #define forr(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define MP make_pair

void prime(vi &vec)
{
    for(int i=2;i<=50;i++)
{
	int flag=1;
for(int j=2;j<i;j++)
{
	if(i%j==0)
	{
		flag=0;
		break;
	}
}
if(flag)
vec.pb(i);
}
}

void solve()
{
	
	int n,m;
	cin>>n>>m;
    vi vec;
	prime(vec);
	int cnt=0;
	for(int i=0;i<=n;i++)
	{ 
	    if(vec[i]==n && vec[i+1]==m)
	    {
			cnt=1;
			break;
		}
	}
	if(cnt)
	{
	    cout<<"YES"<<endl;
	}
	else{
	    cout<<"NO"<<endl;
	}
}

int32_t main()
{
	solve();
}

 


Comments

Submit
0 Comments
More Questions

368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings