编程介的小学生 2019-04-04 22:46 采纳率: 20.5%
浏览 374

素数的筛选的算法的实现的过程,在C程序的思路的程序的设计下怎么做

Problem Description
Prime 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.
A palindromic number is one whose string representation is a palindrome, that is, a string that reads the same backwards and forwards.
You 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.

Input
The 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’].

Output
For 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.

Sample Input
1 10
2 10
3 10
4 24
5 4
0 0

Sample Output
The number of 1-digit palindromic primes < 2^31 in base 10.
What is 4?

The number of 2-digit palindromic primes < 2^31 in base 10.
What is 1?

The number of 3-digit palindromic primes < 2^31 in base 10.
What is 15?

The number of 4-digit palindromic primes < 2^31 in base 24.
What is 0?

The number of 5-digit palindromic primes < 2^31 in base 4.
What is 10?

  • 写回答

1条回答 默认 最新

  • weixin_anvirzh0612 2019-04-05 07:24
    关注

    素数释义:
    曾称质数。一个大于1的正整数,如果除了1和它本身以外,不能被其他正整数整除,就叫素数。如2,3,5,7,11,13,17…。
    C语言判断是否为素数的算法:
    BOOL isPrimeNumber(UINT val)
    {
    int divisor;
    BOOL ret = TRUE;
    if (val == 2) return ret;
    for (divisor = 2; divisor < val; divisor++) {
    if (val%divisor == 0)
    {
    ret = FALSE;
    break;
    }
    }
    return ret;
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条