蓝桥杯每日一题1.13 2018省赛A组1.分数[等比数列求和][约分]

题目描述

1/1 + 1/2 + 1/4 + 1/8 + 1/16 + ....  
每项是前一项的一半,如果一共有20项,求这个和是多少,结果用分数表示出来。 
类似:3/2当然,这只是加了前2项而已。分子分母要求互质。 

输出

按格式输出答案 

题解

https://blog.csdn.net/weixin_43914593/article/details/112517638

等比数列求和

  • formula
  • formula

等差数列求和

  • formula
  • formula

手算2**20-1/2**19,其实可以直接写代码打印出来答案了

约分

int t = __gcd(a, b);   //除去公约数

    cout << a/t << "/" << b/t;

#include<bits/stdc++.h>
using namespace std;

int main(){
	int a = (1 << 20) - 1; //分子
	int b = (1 << 19);     //分母
	int t = __gcd(a, b);   //除去公约数
	cout << a/t << "/" << b/t;
	return 0;
}

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 10100;

ll gcd(ll a,ll b)
{
    ll m;
    m=a%b;
    while(m!=0)
    {
        a=b;
        b=m;
        m=a%b;
    }
    return b;
}

int main()
{
    ll a=pow(2,20)-1;
    ll b=pow(2,19);
    //ll g=gcd(a,b);
    //cout<<(a/g)<<"/"<<(b/g)<<endl;
    cout<<a<<"/"<<b;
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值