第一题
# include<iostream>
# include<cmath>
using namespace std;
bool is_prime(int a)
{
for(int i = 2; i <= a/2; i++){
if(a%i == 0)
return false;
}
return true;
}
int main()
{
int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int count = 11;
int n;
while(cin >> n)
{
bool flag = true;
for(int i = 0; i < count; i++)
{
if(n + 1 == pow(2, p[i]) && is_prime(n)){
cout << "Yes" << endl;
flag = false;
}
}
if(flag)
cout << "No" << endl;
}
return 0;
}
第二题
# include<iostream>
# include<string>
# include<cmath>
# define maxsize 100
using namespace std;
int char2num(char r)
{
return int(r - '0');
}
int str2num(string s)
{
int len = s.size();
int sum = 0;
for(int i = len - 1; i >= 0; i--)
sum += char2num(s.at(i)) * pow(10, len - 1 - i);
return sum;
}
int main()
{
int n;
cin >> n;
while(n--)
{
string re[maxsize];
int count = 0;
string s;
int len, a, b;
cin >> s >> len >> a >> b;
int length = s.size();
// 依次扫描长度为len的子串是否满足条件
for(int i = 0; i <= length - len; i++){
int num = str2num(s.substr(i, len));
if(num % a == b)
re[count++] = s.substr(i, len);
}
cout << count << endl;
for(int i = 0; i < count; i++)
cout << re[i] << endl;
}
return 0;
}