KNOW:Math & Probability
2013-09-26 11:33
302 查看
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 Eratostheneshttp://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:
Create a list of consecutive integers from 2 to n: (2, 3, 4, ...,
n).
Initially, let p equal 2, the first prime number.
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.
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 isfor example, if two coins are flipped the chance of both being heads is
[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 as.
If two events are mutually exclusive then the probability of either occurring is
For example, the chance of rolling a 1 or 2 on a six-sided die is
Not mutually exclusive
If the events are not mutually exclusive thenFor 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
,
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,
and is read "the probability ofA, givenB". It is defined by[21]
If
then
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 is
; 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 be
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相关文章推荐
- sourceinsight 语法不显示高亮 symble无法跳转 不解析
- std::list内存映像
- ubuntu环境下android应用真机调试故障及解决方案
- android分享之微信分享
- HTTP请求报文和响应报文
- 用HTML5 Canvas画的时钟
- 在IIS7中配置Hessian
- 英语学习周小结
- cocos2dx中的touch检查是否选中了控件
- nskeyedunarchiver,从二进制流读取对象用的,
- C语言程序内存分布
- C#透明按钮
- 设计模式之(一)Factory模式
- it笔试题目(性格测评)
- POCO Log库
- oracle回滚段和回滚表空间
- CentOS-6安装使用mongodb
- ZooKeeper源码阅读(四):选举后过程
- windows下 php 导出数据到EXCEL表中
- it笔试题目(技术)