判断质数

Jun 07, 2016 pm 02:55 PM
create judgment integer prime numbers

判断整数是否为质数 无 CREATE FUNCTION CheckPrimeNumber(@No BIGINT) RETURNS TINYINT AS BEGIN IF @No = 1 RETURN 0 DECLARE @maxV BIGINT, @Index BIGINT SET @maxV = @No - 1 SET @Index = 2 WHILE @Index @maxV BEGIN DECLARE @maxV2 BIGINT, @Index2 B

判断整数是否为质数
CREATE FUNCTION CheckPrimeNumber(@No BIGINT) 
RETURNS TINYINT 
AS 
  BEGIN 
      IF @No <= 1 
        RETURN 0 

      DECLARE @maxV  BIGINT, 
              @Index BIGINT 

      SET @maxV = @No - 1 
      SET @Index = 2 

      WHILE @Index < @maxV 
        BEGIN 
            DECLARE @maxV2  BIGINT, 
                    @Index2 BIGINT 

            SET @maxV2 = @maxV 
            SET @Index2 = @Index 

            WHILE @Index2 < @maxV2 
              BEGIN 
                  IF @Index2 * @Index = @No 
                    RETURN 0 

                  SET @Index2 = @Index2 + 1 
              END 

            SET @Index = @Index + 1 
        END 

      RETURN 1 
  END 
GO
SELECT dbo.CheckPrimeNumber(13) -- 返回值1,表示素数,0表示非素数。
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert DateTime to integer in Python? How to convert DateTime to integer in Python? Sep 05, 2023 pm 10:21 PM

The manipulation of date and time values ​​is an important aspect of programming, and the Python language provides a useful built-in module for this called datetime. However, in some cases, you may need to convert a DateTime object to an integer value in order to perform specific operations or calculations. There are multiple ways to convert a DateTime to an integer in Python, each with its own advantages and disadvantages. In this article, we'll take a closer look at these methods and examine when each method is appropriate to use. After reading this article, you will have a complete understanding of how to efficiently convert DateTime objects to integers in Python and be able to choose the most appropriate method for your specific programming task. Method 1: Use timestamp

PHP email detection: Determine whether the email has been sent successfully. PHP email detection: Determine whether the email has been sent successfully. Sep 19, 2023 am 09:16 AM

PHP email detection: Determine whether the email has been sent successfully. When developing web applications, you often need to send emails to communicate with users. Whether it is registration confirmation, password reset, or sending notifications, the email function is an indispensable part. However, sometimes we cannot ensure whether the email is actually sent successfully, so we need to perform email detection and determine whether the email has been sent successfully. This article will introduce how to use PHP to implement this function. 1. Use SMTP server to send emails. First, we need to use SM

Use java's Character.isDigit() function to determine whether a character is a number Use java's Character.isDigit() function to determine whether a character is a number Jul 27, 2023 am 09:32 AM

Use Java's Character.isDigit() function to determine whether a character is a numeric character. Characters are represented in the form of ASCII codes internally in the computer. Each character has a corresponding ASCII code. Among them, the ASCII code values ​​corresponding to the numeric characters 0 to 9 are 48 to 57 respectively. To determine whether a character is a number, you can use the isDigit() method provided by the Character class in Java. The isDigit() method is of the Character class

How to build an AI-oriented data governance system? How to build an AI-oriented data governance system? Apr 12, 2024 pm 02:31 PM

In recent years, with the emergence of new technology models, the polishing of the value of application scenarios in various industries and the improvement of product effects due to the accumulation of massive data, artificial intelligence applications have radiated from fields such as consumption and the Internet to traditional industries such as manufacturing, energy, and electricity. The maturity of artificial intelligence technology and application in enterprises in various industries in the main links of economic production activities such as design, procurement, production, management, and sales is constantly improving, accelerating the implementation and coverage of artificial intelligence in all links, and gradually integrating it with the main business , in order to improve industrial status or optimize operating efficiency, and further expand its own advantages. The large-scale implementation of innovative applications of artificial intelligence technology has promoted the vigorous development of the big data intelligence market, and also injected market vitality into the underlying data governance services. With big data, cloud computing and computing

What does prime mean in c++ What does prime mean in c++ May 07, 2024 pm 11:33 PM

prime is a keyword in C++, indicating the prime number type, which can only be divided by 1 and itself. It is used as a Boolean type to indicate whether the given value is a prime number. If it is a prime number, it is true, otherwise it is false.

What are the regular expressions for integers? What are the regular expressions for integers? Nov 14, 2023 pm 04:11 PM

The regular expressions for integers are: 1. Match positive integers: ^[1-9]\d*$; 2. Match negative integers: ^-[1-9]\d*$; 3. Match positive integers and negative integers :^-?\d+$; 4. Match non-zero integers: ^(0|[1-9]\d*)$; 5. Match integers (including zero): ^-?\d+$.

What does prime mean in c++ What does prime mean in c++ May 07, 2024 pm 11:24 PM

In C++, prime refers to a prime number, a natural number that is greater than 1 and is only divisible by 1 and itself. Prime numbers are widely used in cryptography, mathematical problems and algorithms. Methods for generating prime numbers include Eratostheian sieve, Fermat's Little Theorem, and the Miller-Rabin test. The C++ standard library provides the isPrime function to determine whether it is a prime number, the nextPrime function returns the smallest prime number greater than a given value, and the prevPrime function returns the smallest prime number less than a given value.

Sharepoint install SSL certificate? Sharepoint install SSL certificate? Feb 19, 2024 am 11:27 AM

Installing an SSL certificate on SharePoint is a critical step in securing your website and providing an encrypted connection. By following the correct installation steps, you can ensure the security of your website data, improve your ranking in search engines, and provide a better user experience for your visitors. Get an SSL Certificate Contact a trusted Certificate Authority (CA) to purchase an SSL certificate. Provide the required authentication and domain ownership verification information. After completing the verification process, you will receive the SSL certificate file. Prepare the Certificate File Open your SSL certificate file using a text editor. Copy the certificate contents to a new text file. Save the file as yourdomain.cer, making sure to change "yourdomain&#8221

See all articles