﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gavin&#039;s Blog &#187; 数据结构/算法</title>
	<atom:link href="http://laigw.name/cat/tech/algorithm/feed" rel="self" type="application/rss+xml" />
	<link>http://laigw.name</link>
	<description>Keep it simple, stupid. Simplicity is beauty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>一些基本算法（强烈推荐）</title>
		<link>http://laigw.name/post/85.html</link>
		<comments>http://laigw.name/post/85.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 08:05:09 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[数据结构/算法]]></category>
		<category><![CDATA[基本算法]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=85</guid>
		<description><![CDATA[大学搞ACM竞赛期间，在网上遇见这个好东东，觉得这份资料对算法的训练的确很有帮助。不过它是用Pascal写的，可能对习惯了C系语言的同学有点不习惯。现在先贴出其原代码，有时间的话再把它们翻译成C/C++。
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
一、数论算法
1．求两数的最大公约数

function gcd(a,b:integer):integer;
begin
if b=0 then gcd:=a
else gcd:=gcd (b,a mod b);
end ;
2．求两数的最小公倍数
function lcm(a,b:integer):integer;
begin
if a
lcm:=a;
while lcm mod b&#62;0 do inc(lcm,a);
end;
3．素数的求法
A.小范围内判断一个数是否为质数：
function prime (n: integer): Boolean;
var I: integer;
begin
for I:=2 to trunc(sqrt(n)) do
if n mod I=0 then begin
prime:=false; exit;
end;
prime:=true;
end;
B.判断longint范围内的数是否为素数（包含求50000以内的素数表）：
procedure getprime;
var
i,j:longint;
p:array[1..50000] of boolean;
begin
fillchar(p,sizeof(p),true);
p[1]:=false;
i:=2;
while i&#60;50000 do begin
if p[i] then begin
j:=i*2;
while j&#60;50000 do begin
p[j]:=false;
inc(j,i);
end;
end;
inc(i);
end;
l:=0;
for i:=1 to 50000 do
if p[i] then begin
inc(l);pr[l]:=i;
end;
end;{getprime}
function prime(x:longint):integer;
var i:integer;
begin
prime:=false;
for i:=1 [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/85.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

