Stern-Brocot Tree

  • 作用:
    用来找一个区间内的最简分数,并按序输出
  • 源代码:
void solve(int a,int b,int c,int d){                  //遍历区间为a/b 到 c/d
    if(b+d>n) {  
        return;
    }
    solve(a,b,a+c,b+d);
    printf("%d/%d\n",a+c,b+d);
    solve(a+c,b+d,c,d);
}

solve(0,1,1,1);            
posted @ 2021-01-28 18:59  z_thorn  阅读(86)  评论(0编辑  收藏  举报