题目描述Description输入二个正整数x0,y0(2 2 #include 3 int ojld(int i,int j)//最大公约数(递归) 4 { 5 if(i==0)return j; 6 ojld(j%i,i); 7 } 8 int main...
分类:
其他好文 时间:
2015-05-01 22:29:24
阅读次数:
213
Another Easy Problem
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice FZU
1753
Appoint description:
xietutu (2013-03-13)System Crawler ...
分类:
其他好文 时间:
2015-04-30 21:56:39
阅读次数:
195
关于尾递归 ,使用Scala的两个例子展示尾递归的定义和简单实现。例子比较求最大公约数的函数def gcd(a: Int, b: Int): Int =
if (b == 0) a else gcd(b, a % b)计算的展开是尾递归的,gcd(14, 21)
-> if (21 == 0) 14 else gcd(21, 14 % 21)
-> if (false) 14 else gcd(...
分类:
其他好文 时间:
2015-04-29 23:30:49
阅读次数:
178
#includeint gcd(int a,int b){ int t,max,min; if(a>b) { max=a; min=b; } else { max=b; min=a; } while(min!=max) { t=max-min; if(t>min) { max=t;...
分类:
其他好文 时间:
2015-04-27 00:11:54
阅读次数:
155
递归gcd()
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
特点及意义
最大公约数指某几个整数共有因子中最大的一个。
例如,12和30的公约数有:1、2、3、6,其中6就是12和30的最大公约数。
两...
分类:
其他好文 时间:
2015-04-26 09:21:44
阅读次数:
440
/*欧几里德算法:辗转求余 原理: gcd(a,b)=gcd(b,a mod b) 当b为0时,两数的最大公约数即为agetchar()会接受前一个scanf的回车符*/#includevoid main(){ int temp; int a,b; scanf("%d",&a); scanf("%d...
分类:
编程语言 时间:
2015-04-25 19:37:28
阅读次数:
169
// 求两个数m和n的最大公约数(辗转相除法)
#include
int yue( int x, int y )
{
int temp;
int tem;
// 保证分母不为0
if( y == 0 )
{
x = temp;
temp = y;
y = x;
}
// 辗转相除法
while( tem )
{
tem = x % y;
x = y;
...
分类:
编程语言 时间:
2015-04-23 13:21:51
阅读次数:
187
裴蜀定理
(1)a,b互质的充要条件是:存在整数x,y使ax+by=1
(2)设a1,a2,a3......an为n个整数,d是它们的最大公约数,那么存在整数x1......xn使得x1*a1+x2*a2+...xn*an=d
(3)如果a1...an互质(不一定是两两互质),那么存在整数x1......xn使得x1*a1+x2*a2+...xn*an=1
(4)对任何整数a,b和它们的最...
分类:
其他好文 时间:
2015-04-22 22:23:46
阅读次数:
316
解法一:
辗转相除法,使用原理为f(x,y)表示x,y的最大公约数,取k=x/y,b=x%y,则x=ky+b,如果一个数能够同时整除x和y,则必能同时整除b和y,而能够同时整除b和y的数也必能同时整除x和y,即x和y的公约数与b和y的公约数相同的,其最大公约数也是相同的,则有f(x,y)=f(y,x%y)(y>0).
具体代码如下:
int gcd(int x,int y)
{...
分类:
其他好文 时间:
2015-04-21 09:54:49
阅读次数:
126
1 #include 2 using namespace std; 3 4 int gcd(int m , int n) 5 { 6 int r; 7 while(n!=0) 8 { 9 r = m%n;10 m = n;11 ...
分类:
编程语言 时间:
2015-04-21 09:26:19
阅读次数:
143