KNOW:Math & Probability

Prime Number

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. (1 is not a prime number).

A natural number greater than 1 that is not a prime number is called a composite number.

every positive integer can be decomposed into a product of primes.

84 = 2^2 * 3^1 * 5^0 * 7^1

Let x = 2^i1 * 3^i2 * 5^i3 *  ...
Let y = 2^k1 * 3^k2 * 5^k3 * ...
If x%y == 0, then for all i, ji <= ki.


In fact, the greatest common divisor of x and y will be:
gcd(x, y) = 2^min(i1,k1) * 3^mln(i2,k2) * ...
The least common multiple of x and y will be:
lcm(x, y) = 2^max(i1,k1) * 3^max(i2,k2) * ...

gcd(x, y) * lcm(x, y) = x*y

Checking for Primality

boolean prime(int n)
{
    if(n < 2)
         return false;
    
    int sqrt = (int) sqrt(n);
    for(int i = 2; i <= sqrt; ++i)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}

Generating a List of Primes

The Sieve of Eratosthenes

http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

All non-prime numbers are divisible by a prime number.

To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method:

  1. Create a list of consecutive integers from 2 to n: (2, 3, 4, ..., n).
  2. Initially, let p equal 2, the first prime number.
  3. Starting from p, count up in increments of p and mark each of these numbers greater thanp itself in the list. These will be multiples ofp: 2p, 3p, 4p, etc.; note that some of them may have already been marked.
  4. Find the first number greater than p in the list that is not marked. If there was no such number, stop. Otherwise, letp now equal this number (which is the next prime), and repeat from step 3.

Probability

Independent probability

If two events, A and B are independent then the joint probability is

P(A \mbox{ and }B) =  P(A \cap B) = P(A) P(B),\,

for example, if two coins are flipped the chance of both being heads is \tfrac{1}{2}\times\tfrac{1}{2} = \tfrac{1}{4}.[20]

Mutually exclusive

If either event A or event B or both events occur on a single performance of an experiment this is called the union of the eventsA andB denoted asP(A \cup B). If two events are mutually exclusive then the probability of either occurring is

P(A\mbox{ or }B) =  P(A \cup B)= P(A) + P(B).

For example, the chance of rolling a 1 or 2 on a six-sided die is P(1\mbox{ or }2) = P(1) + P(2) = \tfrac{1}{6} + \tfrac{1}{6} = \tfrac{1}{3}.

Not mutually exclusive

If the events are not mutually exclusive then

\mathrm{P}\left(A \hbox{ or } B\right)=\mathrm{P}\left(A\right)+\mathrm{P}\left(B\right)-\mathrm{P}\left(A \mbox{ and } B\right).

For example, when drawing a single card at random from a regular deck of cards, the chance of getting a heart or a face card (J,Q,K) (or one that is both) is\tfrac{13}{52} + \tfrac{12}{52} - \tfrac{3}{52} = \tfrac{11}{26}, because of the 52 cards of a deck 13 are hearts, 12 are face cards, and 3 are both: here the possibilities included in the "3 that are both" are included in each of the "13 hearts" and the "12 face cards" but should only be counted once.

Conditional probability

Conditional probability is the probability of some event A, given the occurrence of some other eventB. Conditional probability is written\mathrm{P}(A \mid B), and is read "the probability ofA, givenB". It is defined by[21]

\mathrm{P}(A \mid B) = \frac{\mathrm{P}(A \cap B)}{\mathrm{P}(B)}.\,

If \mathrm{P}(B)=0 then\mathrm{P}(A \mid B) is formallyundefined by this expression. However, it is possible to define a conditional probability for some zero-probability events using aσ-algebra of such events (such as those arising from acontinuous random variable).[citation needed]

For example, in a bag of 2 red balls and 2 blue balls (4 balls in total), the probability of taking a red ball is1/2; however, when taking a second ball, the probability of it being either a red ball or a blue ball depends on the ball previously taken, such as, if a red ball was taken, the probability of picking a red ball again would be1/3 since only 1 red and 2 blue balls would have been remaining.

二项式公式

aX^2 + bX + c = 0

[-b+/-根号(b^2-4ac)]/2a

Two-Dimensional Problem

How to represent a line:

1. two points (x1, y1) & (x2, y2)

2. slope and y-intercept (s1, y1)...(与Y轴交点)

Problems

CCI 7.5, 7.6




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值