题目描述

在这里插入图片描述

思路分析

方案一

等比数列,再进行约分
在这里插入图片描述

在这里插入图片描述

方案二

求和
约分:辗转相除法求最大公约数

package TEST;

class Main{
    static int GCD(int x,int y){//求最大公约数
        if(y==0){
            return x;
        }
        return GCD(y,x%y);//是x%y,不是x/y
    }
    public static void main(String[] args) {

        int bot=1;
        int top=1;
        for (int i = 1; i <20 ; i++) {
            top=2*top+1;
            bot=bot*2;
        }
        System.out.println(top+" "+bot);

        int gcd=top>bot?GCD(top,bot):GCD(bot,top);//没有if
        System.out.println(gcd);
        System.out.println(top/gcd+"/"+bot/gcd);

    }

}

答案

1048575/524288

Logo

一站式虚拟内容创作平台,激发创意,赋能创作,进入R空间,遇见同道,让优质作品闪耀发光。​

更多推荐