2010/03/10
| |
一、辗转相除法:
      大数除以小数    余数1
      小数除以余数1    余数2
      余数1除以余数2    余数3
      若余数3为0,则余数2为所求,否则一直辗转相除
int gys(int m,int n)
{
  int t,r;
  if(m<n)
  {t=m;m=n;n=t;}
  r=m%n;
  while(r!=0)
  {
    m=n;
    n=r;
    r=m%n;
  }
  return n;
}


二、更相减损法

int jsf(int a,int b)
{
  while(a!=b)
  {
    if(a>b)
      a-=b;
    else
      b-=a;
  }

  return b;
}
不指定 2010/03/10 10:30, wxxslt, 网站建设 » C/C++, 评论(0), 阅读(639)
发表评论
表情
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 
Theme by Marshal. Powered by Bo-Blog 2.1.1 ReleaseCode detection by Bug.Center.Team