A. PolandBall and Hypothesis
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard 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.
题意;给你n,找出最小的m使得n*m+1不是素数。
题解:暴力即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int solve(int x)
{
for(int j=2;j<x;j++)
{
if(x%j==0) return 1;
}
return 0;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=1000;i++)
{
if(solve(n*i+1))
{
cout<<i<<endl;
return 0;
}
}
}
B. PolandBall and Game
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can’t say a new word loses.
You’re given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
Input
The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively.
Then n strings follow, one per line — words familiar to PolandBall.
Then m strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players.
Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
Output
In a single line of print the answer — “YES” if PolandBall wins and “NO” otherwise. Both Balls play optimally.
Examples
Input
5 1
polandball
is
a
cool
character
nope
Output
YES
Input
2 2
kremowka
wadowicka
kremowka
wiedenska
Output
YES
Input
1 2
a
a
b
Output
NO
Note
In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
题意:A ,B两份分别知道n,m个单词,每次每人说一个单词,说过的不准说,问A能否获胜.
题解: 两人先说两个人都会的单词.再说自己会的单词,判断重复的单词的奇偶性.再比较大小即可.
代码:
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
string str;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
cin>>str;
mp[str]++;
}
int tmp=0;
for(int i=0;i<m;i++)
{
cin>>str;
if(mp[str]>0)
tmp++;
}
n=n-tmp+tmp%2;
m=m-tmp;
if(n>m) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}