PAT(甲级)2019年春季考试题解

本来想用PAT抵浙大的机试成绩,结果忘记时间错过了报名春季的考试(其实是只刷了十几题心里没底想晚点再报名,后来就忘记了)…然后看题库发现现在PTA平台不会同步更新最新的考试题目了,要去教育超市花钱买(稍微有点坑),不过好处是花了钱我才能更加重视…于是在今天–在考前的一周,下午一点半准时模拟了下周的考试,所幸练习的结果不错,要是考试也能有这样的发挥就好了。
在这里插入图片描述

7-1 Sexy Primes (20 分)

Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “six”. (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)

Now given an integer, you are supposed to tell if it is a sexy prime.

Input Specification:
Each input file contains one test case. Each case gives a positive integer N (≤ 1 0 8 10^8 108​​ ).

Output Specification:
For each case, print in a line Yes if N is a sexy prime, then print in the next line the other sexy prime paired with N (if the answer is not unique, output the smaller number). Or if N is not a sexy prime, print No instead, then print in the next line the smallest sexy prime which is larger than N.

Sample Input 1:
47
Sample Output 1:
Yes
41
Sample Input 2:
21
Sample Output 2:
No
23

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<unordered_map>
#include<unordered_set>
using namespace std;
const int maxn=100;
const int INF=0x3f3f3f3f;
bool isprime(long long a) {
   
	if(a<=1) return false;
	for(long long i=2; i*i<=a; i++) {
   
		if(a%i==0) return false;
	}
	return true;
}
int main() {
   
	int n;
	scanf("%d",&n);
	if(isprime(n)) {
   
		if(isprime(n-6)) printf("Yes\n%d",n-6);
		else if(isprime(n+6)) printf("Yes\n%d",n+6);
		else {
   
			for(int i=n+1;; i++) {
   
				if(isprime(i) && (isprime(i+6) || isprime(i-6))) {
   
					printf("No\n%d",i);
					break;
				}
			}
		}
	} else {
   
		for(int i=n+1;; i++) {
   
			if(isprime(i) && (isprime(i+6) || isprime(i-6))) {
   
				printf("No\n%d",i);
				break;
			}
		}
	}
	return 0;
}

7-2 Anniversary (25 分)

Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID’s of all her alumni. Now your job is to write a program to count the number of alumni among all the people who come to the celebration.

Input Specification:
Each input file contains one test case. For each case, the first part is about the information of all the alumni. Given in the first line is a positive integer N (≤ 1 0 5 10^5 105​​ ). Then N lines follow, each contains an ID number of an alumnus. An ID number is a string of 18 digits or the letter X. It is guaranteed that all the ID’s are distinct.

The next part gives the information of all the people who come to the celebration. Again given in the first line is a positive integer M (≤ 1 0 5 10^5 105​​ ).Then M lines follow, each contains an ID number of a guest. It is guaranteed that all the ID’s are distinct.

Output Specification:
First print in a line the number of alumni among all the people who come to the celebration. Then in the second line, print the ID of the oldest alumnus – notice that the 7th - 14th digits of the ID gives one’s birth date. If no alumnus comes, output the ID of the oldest guest instead. It is guaranteed that such an alumnus or guest is unique.

Sample Input:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
Sample Output:
3
150702193604190912

#include<iostream>
#
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值