PKU1165 The Primes



The Primes


问题描述 :nnnnn|---|---|---|---|---|nn| 1 | 1 | 3 | 5 | 1 |nn|---|---|---|---|---|nn| 3 | 3 | 2 | 0 | 3 |nn|---|---|---|---|---|nn| 3 | 0 | 3 | 2 | 3 |nn|---|---|---|---|---|nn| 1 | 4 | 0 | 3 | 3 |nn|---|---|---|---|---|nn| 3 | 3 | 3 | 1 | 1 |nn|---|---|---|---|---|nn(Figure 1)nnnnnFigure 1 shows a square. Each row, each column and the two diagonals can be read as a five digit prime number. The rows are read from left to right. The columns are read from top to bottom. Both diagonals are read from left to right. Write a program that constructs such squares:nnnnn The prime numbers must have the same digit sum (11 in the example).nnn The digit in the top left-hand corner of the square is pre-determined (1 in the example).nnn A prime number may be used more than once in the same square.nnn If there are several solutions, all must be presented.nnn A five digit prime number cannot begin with zeros, ie 00003 is NOT a five digit prime number. nnnn nn输入:nnnYour program is to read from standard input. First the digit sum of prime numbers and then the digit in the top left-hand corner of the square. The file contains two lines. There will always be a solution to the given test data. n输出:nnnYour program is to write to standard output. Output five lines for each solution found, where each line in turn consists of a five digit prime number. The solutions are sorted by the prime in the first row, then by the prime in the second row,etc. Output a blank line after each solution.n样例输入:nn11n1n样例输出:nn11351n14033n30323n53201n13313nn11351n33203n30323n14033n33311nn13313n13043n32303n50231n13331

Palindromic Primes Category in Jeopardy!


Problem DescriptionnPrime numbers are defined as follows: a number is prime if it is greater than 1 and is evenly divisible only by itself and 1. Note that by definition neither zero nor one is a prime number.nA palindromic number is one whose string representation is a palindrome, that is, a string that reads the same backwards and forwards.nYou are on the clue crew preparing questions for the category “Palindromic Primes” and are to write a program to generate the answer and responding question in Jeopardy! style.n nnInputnThe input file contains a series of number pairs (with white space separating them) specifying individual problems, ending with a pair of zeroes. The first number gives the number of digits for the numbers to be considered, the second number gives the base in which the numbers are to be generated. The numbers are separated by a single space. You are assured that all palindromic primes for this problem can be represented in the range of a standard 32-bit signed integer. The bases allowed are integer bases between 2 and 36 — with bases above base ten handled as extensions of hexadecimal. This means that the valid numeric digits are in the range [‘0’..‘9’] and [‘a’..‘z’].n nnOutputnFor each number, generate one line giving the number of digits and the base as the answer and then on the next line the number of palindromic primes found as the question as shown in the sample output. Each output pair should be separated by a blank line.n nnSample Inputn1 10n2 10n3 10n4 24n5 4n0 0n nnSample OutputnThe number of 1-digit palindromic primes < 2^31 in base 10.nWhat is 4?nnThe number of 2-digit palindromic primes < 2^31 in base 10.nWhat is 1?nnThe number of 3-digit palindromic primes < 2^31 in base 10.nWhat is 15?nnThe number of 4-digit palindromic primes < 2^31 in base 24.nWhat is 0?nnThe number of 5-digit palindromic primes < 2^31 in base 4.nWhat is 10?n

Sum of Different Primes


A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k, you should count the number of ways to express n as a sum of k different primes. Here, two ways are considered to be the same if they sum up the same set of the primes. For example, 8 can be expressed as 3 + 5 and 5 + 3 but the are not distinguished.nnWhen n and k are 24 and 3 respectively, the answer is two because there are two sets 2, 3, 18 and 2, 5, 17 whose sums are equal to 24. There are not other sets of three primes that sum up to 24. For n = 24 and k = 2, the answer is three, because there are three sets 5, 19, 7, 17 and 11, 13. For n = 2 and k = 1, the answer is one, because there is only one set 2 whose sum is 2. For n = 1 and k = 1, the answer is zero. As 1 is not a prime, you shouldn��t count 1. For n = 4 and k = 2, the answer is zero, because there are no sets of two different primes whose sums are 4.nnYour job is to write a program that reports the number of such ways for the given n and k.nnInputnnThe input is a sequence of datasets followed by a line containing two zeros separated by a space. A dataset is a line containing two positive integers n and k separated by a space. You may assume that n �� 1120 and k �� 14.nnOutputnnThe output should be composed of lines, each corresponding to an input dataset. An output line should contain one non-negative integer indicating the number of the ways for n and k specified in the corresponding dataset. You may assume that it is less than 231.nnSample Inputnn24 3 n24 2 n2 1 n1 1 n4 2 n18 3 n17 1 n17 3 n17 4 n100 5 n1000 10 n1120 14 n0 0nSample Outputnn2 n3 n1 n0 n0 n2 n1 n0 n1 n55 n200102899 n2079324314


  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他