1. Maximum common approx. (GCD)
(1) If both A and B are 0, gcd does not exist
(2) If one of A and B is 0, then GCD is the non-zero one in A and B.
(3) If neither a nor B is 0, the new A = B, B = A % B, and then repeat the process.
Non-recursion
int gcd(int a, int b){ while (b != 0){ int t = a%b; a = b; b = t; } return a;}Recursion
int gcd(int a,int b){ return b!=0?gcd(b,a%b):a;}
2. Minimum Public multiple (LCM)
The least common multiple is the product of two
To determine the prime number, you can open the given number and use this value to divide the number from 1 to open the house or only the largest integer smaller than the given one. If the number cannot be divisible, this is a prime
write a program that would solve such problems.The input consists of one to the data sets, followed by a final line containing only 0. Each data set starts with a line containing only a number n, which is the number of villages, 1 The output is an integer per line for each data set:the minimum cost of aacms per month to maintain a road system that C Onnect all the villages. Caution:a Brute force solution t
The basic content of the unique decomposition theory:
Any positive integer greater than 1 can represent the product of several prime numbers, and the representation method is unique. In other words, a number can be uniquely divided into the product of a prime factor. Therefore, this theorem is also called the unique decomposition theorem.
Example: 50 = (2 ^ 1) *
Carmichael Numbers
An important topic nowadays in computer science is cryptography. some people even think that cryptography is the only important field in computer science, and that life wocould not matter at all without cryptography. alvaro is one of such persons, and is a set of cryptographic procedures for cooking paella. some of the cryptographic algorithms he is implementing make use of big prime numbers. however, checking if a big
Description
In mathematics, a squarefree number is one which are divisible by no perfect squares, except 1. For example, Square-free but, as it is divisible by 9 = 3^2. Now you are need to determine whether an integer is Squarefree or.
Input
The ' The ' contains an integer T indicating the number of test cases.
For each test case, the there is a single line contains an integer N.
Technical Specification 1
Let's take a look at the most classic Eratsteni sieve method. Time Complexity of O (n loglog N)
int ANS[MAXN];
void Prime (int n)
{
int cnt=0;
memset (prime,1,sizeof (Prime));
prime[0]=prime[1]=0;
for (int i=2;i
Obviously, when a n
Tags: Number Theory
N! Number of zeros
Time limit 1000 ms
Memory limit 65536 K
Description
Read N from the input and obtain n! The number of zeros at the end.
Input
The input has several rows. There is an integer m on the first line, indicati
Scan the following two-dimensional code to download and install the Ape Tutorial app, and after opening, search for the teacher's name " Zhao Yin" to enroll in this course.1. Prove that: for any given positive integer $n $, there is an infinite number of positive integers $a $, so that $n ^4 + a$ is composite.Answer:Make $a = 4m^4$, $m \in\mathbf{z}$, $ $n ^4 + 4m^4 = (n^2 + 2m^2) ^2-4m^2n^2$$ $$= (n^2 + 2m^2 + 2mn) (n^2 + 2m^2-2mn) $$ easy to know,
The simplest method of screening prime numbers is to remove the multiples of SO 2 from 2, and then remove the multiples of 3 from 3. According to this, it is easy to write the code. The code below is to screen the prime number method to obtain the prime number less than 100
1. The definition of prime number (prime number): A tree that is divisible only by 1 and itself
2, how to judge a prime is not primes: Use this number to remove 2 to sqrt (this number)
The so-called prime is the number of numbers that cannot be divisible by any other integer except 1 and itself.
To judge a number n (n>=3) method: N as dividend, will be 2 to (n-1) each integer divisor, if all can not be divisible, then n is prime.
Algorithm Analysis:
S1:
I once went to a company interview, encountered such a topic: ask for the number of primes within 1000 how many? Use multithreading to achieve, and give time to consume. I thought for a while and didn't come up with a multi-threaded solution. Today because of the opportunity, I talk about my solution.This problem obviously has to consider two questions:1, multi-threaded issues2, algorithm performance proble
C language: implements a function to determine whether a number is a prime number.Implement a function to determine whether a number is a prime number. Program:
# Include
Result 1: Enter a positive integer greater than 1. If 88 is not a
Label: style blog Io color for SP Div on Log
Gcd (x, y) (1
This complexity is unacceptable,
Then, we can consider enumerating K and calculating Σ PHI (Q/K) (k is the prime number within N, and Q is a multiple of K within N), that is, Σ [PHI (1) + PHI (2) + PHI (3) +... + PHI (p)] (P = N/K)
Prefix of PHI and can be preprocessed in rough.
However, (x, y) and (Y, x) are different. Therefore, w
/*************************************** ** *** AUTHER: liuyongshui* ****** DATE: 2013 \ 4 \ 7* ** LANGUAGE: C* ** QUESTION: determines whether a number is a prime number.****************************************/
# Include
Int main (){Int I;Int num;Int flag = 1; // flag
Printf ("enter an integer greater than 1 (This number
Number of digits of prime number
problem:117
Time limit:1000ms
Memory limit:65536k
Description
Xiao Ming is a clever boy and has a strong interest in number theory.He found that it was difficult t
;//}///**************************************************/ /**************************************/ Do //I love this code of control input.{//scanf"%d",inch[i++]);//It's simple, but it's ingenious .} while(inch[I1]);// /********************************///Generous Elegancea[0]=1; for(intj=1; j) {Count=1; printf ("Case %d:\n", j);//J Display the number of input data if(! (inch[J-1]%2)||inch[J-1]==1)
also be improved. The more improvements, the faster the execution efficiency. For example, because an even number cannot be a prime number, it must be divisible by 2, so we can discard all the even numbers, which will reduce the time by half, and the space will also be reduced by half. If it is billions, just open an array of 0.5 billion, the I in the for loop s
we all know that. RSA 's cryptographic security is the ability to find a suitable large prime, and now there are many ways to judge large primes, such as Fermat primality test or miller-rabin primality test , and here I used the miller-rabin primality test algorithm, the specific theory I wrote below. The theoretical basis of the algorithm:
Fermat theore
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.