蓝桥杯历届-埃及分数

来源:互联网 发布:禁止上网软件 编辑:程序博客网 时间:2024/05/20 21:44

蓝桥杯历届-埃及分数


标题:埃及分数    古埃及曾经创造出灿烂的人类文明,他们的分数表示却很令人不解。古埃及喜欢把一个分数分解为类似: 1/a + 1/b 的格式。    这里,a 和 b 必须是不同的两个整数,分子必须为 1    比如,2/15 一共有 4 种不同的分解法(姑且称为埃及分解法):1/8 + 1/1201/9 + 1/451/10 + 1/301/12 + 1/20    那么, 2/45 一共有多少个不同的埃及分解呢(满足加法交换律的算同种分解)? 请直接提交该整数(千万不要提交详细的分解式!)。    请严格按照要求,通过浏览器提交答案。    注意:只提交分解的种类数,不要写其它附加内容,比如:说明性的文字
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int gcd(int a, int b) {      if (b == 0) return a;      int d = a % b;      return gcd(b, d);  }  int main() {    int count = 0;    for (int i = 2; i <= 9900; i++) {        for (int j = i+1; j <= 9900; j++) {            int a = i, b = j;            int sum1 = a*b, sum2 = a+b;            int t = gcd(sum2, sum1);            int a1 = sum1/t, a2 = sum2/t;            if (a1 == 45 && a2 == 2) {                printf("1/%d + 1/%d = 2/45\n", a, b);                count++;            }         }    }    printf("%d\n", count);      return 0;}

求出其最大公约数即可
答案是7


0 0