发布时间 : 星期四 文章华东师范大学计算机机试真题更新完毕开始阅读4f0ac327bb1aa8114431b90d6c85ec3a86c28b5a
int i; int j;
prime[0]=prime[1]=false;//不是素数 prime[2]=true;//是素数 for(i=3;i<=10005;i+=2) {
prime[i]=true;//是素数
prime[i+1]=false;//不是素数 除0和2之外的偶数都不是素数 }
for(i=3;i<=10005;i+=2) {
if(prime[i]==true)//是素数 { j=i+i;
while(j<=10005) {
prime[j]=false;//不是素数 j+=i; } } } }
int main() { int c; int n;
init();//初始化
while(scanf(\{
while(c--) {
scanf(\int sum=0; int i;
for(i=2;i<=n/2;i++) {
if(prime[i]==true&&prime[n+1-i]==true) sum++; }
sum*=2;
if(n%2==1)//n为奇数 {
if(prime[n/2+1]==true) sum+=1;
}
printf(\} }
return 0; }
求最大公约数和最小公倍数
GCD and LCM Description
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b (0 < a, b ≤ 44000).
Input
The first line of input gives the number of cases, N(1 ≤ N ≤ 100). N test cases follow. Each test case contains two interger a and b separated by a single space in a line.
Output
For each test case, print GCD and LCM separated by a single space in a line.
Sample Input 2 8 6
5000 3000
Sample Output 2 24
1000 15000
#include
int gcd; int t1,t2; t1=a; t2=b;
gcd=t1%t2; while(gcd!=0) {
t1=t2; t2=gcd; gcd=t1%t2;
}
return t2; }
int main() { int n; int a,b;
while(scanf(\{
while(n--) {
scanf(\
printf(\} }
return 0; }
排序后求位置处的数
Sort it… Description
There is a database,partychen want you to sort the database’s data in the order from the least up to the greatest element,then do the query: \natural number in a range from 1 to N.
It should be able to process quickly queries like this.
Input
The standard input of the problem consists of two parts. At first, a database is written, and then there's a sequence of queries. The format of database is very simple: in the first line there's a number N (1<=N<=100000), in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queries K (1 <= K <= 100) is written, and in the next K lines there are queries one in each line. The query \i.
Output
The output should consist of K lines. In each line there should be an answer to the corresponding query. The answer to the query \the order from the least up to the greatest element).
Sample Input 5
7 121 123 7 121 3 3 2 5
Sample Output 121 7 123
#include
while(scanf(\{
for(i=1;i<=n;i++)
scanf(\scanf(\for(i=1;i<=k;i++) scanf(\sort(num+1,num+1+n); for(i=1;i<=k;i++)
printf(\}
return 0; }
*路由器连接
Hub Connection plan Description
Partychen is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables.