题目描述
1/1 + 1/2 + 1/4 + 1/8 + 1/16 + ....
每项是前一项的一半,如果一共有20项,求这个和是多少,结果用分数表示出来。
类似:3/2当然,这只是加了前2项而已。分子分母要求互质。
输出
按格式输出答案
题解
https://blog.csdn.net/weixin_43914593/article/details/112517638
等比数列求和
等差数列求和
手算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;
}