最近在看最大公约数的一些性质,很有意思,有些性质simple,beautiful,乍看上很明显,但依旧需要思索一番才敢确认嘛。 如wikiepdia给出的这条性质: 现证明第二行: 不妨假设最大公约数为d,则a,b可以写成a=dx,b=dy的形式(乘积!非微分哦)。 于是a-b=d(x-y),于是命题证明变成要证明a-b=d(x-y)和b的最大公约数即是a与b的最大公约数。 而a-b=d(x-y... Read More
posted @ 2012-06-23 19:02 Dance With Automation Views(3350) Comments(3) Diggs(2)
首先给出wikipedia上Stein算法的理论依据: The algorithm reduces the problem of finding the GCD by repeatedly applying these identities: gcd(0, v) = v, because everything divides zero, and v is the largest number ... Read More
posted @ 2012-06-23 19:00 Dance With Automation Views(361) Comments(1) Diggs(0)
use poly ADT: 1: #include <stdio.h> 2: #include <stdlib.h> 3: #define MAX_DEGREE 9999 4: 5: struct polynomial 6: { 7: int coeff_array[MAX_DEGREE]; 8: int maxpower; ... Read More
posted @ 2012-06-23 18:59 Dance With Automation Views(306) Comments(0) Diggs(0)
簊亍书丄旳峛孒,①個潲嶶攺進了①些旳冪運匴,加了一个简单的check,以及改成了位运算。 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <limits.h> 4: 5: unsigned long power(int base,int n) 6: { 7: //a simple... Read More
posted @ 2012-06-23 18:59 Dance With Automation Views(143) Comments(0) Diggs(0)
use simple linked list ADT: about the running time of polynode multiply2(const polynode p1,const polynode p2), assume size of p1 is M,size of p2 is N, the result should be: M*N+2N+3N+4N+5N+…+(M-1)N=M*... Read More
posted @ 2012-06-23 18:58 Dance With Automation Views(361) Comments(0) Diggs(0)
header file: 1: #ifndef LINKLIST_H_INCLUDED 2: #define LINKLIST_H_INCLUDED 3: 4: struct node; 5: typedef struct node mynode; 6: typedef struct node *ptr_to_node; 7: typedef ptr_... Read More
posted @ 2012-06-23 18:58 Dance With Automation Views(126) Comments(0) Diggs(0)