Prime Algorithm

The Prime Factorization Algorithm is a mathematical procedure used to find the prime factors of a given number. Prime factors are the prime numbers that can be multiplied together to produce the original number. The algorithm involves dividing the number by successive prime numbers, starting from the smallest prime (which is 2), and continuing until the quotient is a prime number. The main goal of this algorithm is to break down a composite number into its simplest building blocks, which are its prime factors. This allows for a better understanding of the number's properties, composition, and can also be useful in various mathematical and cryptographic applications. In the process of prime factorization, we first check if the given number is divisible by 2, which is the smallest prime number. If it is divisible, we divide the number by 2 and continue this process until the quotient is not divisible by 2 anymore. Then, we move on to the next smallest prime number (which is 3) and perform the same steps. We continue this process of dividing by successive prime numbers until the quotient is a prime number itself, at which point the process is complete. The list of prime divisors obtained in this process represents the prime factorization of the original number. This algorithm can be implemented using various programming languages and techniques, and it is a fundamental concept in number theory and the study of prime numbers.
#include <stdio.h>
#include <math.h>

int isPrime(int x) {
    if (x == 2) {
        return 1;
    }
    if (x < 2 || x % 2 == 0) {
        return 0;
    }
    
    double squareRoot = sqrt(x);
    
    for (int i = 3; i <= squareRoot; i += 2) {
        if (x % i == 0)
            return 0;
    }
    return 1;

}

int main() {
    int a;
    printf("Input a number to see if it is a prime number:\n");
    scanf("%d", &a);
    if (isPrime(a))
        printf("%d is a prime number.\n", a);
    else
        printf("%d is not a prime number.\n", a);
    return 0;
}

LANGUAGE:

DARK MODE: