鱼C论坛

 找回密码
 立即注册
查看: 4176|回复: 18

题目33:找出具有一种奇怪约分性质的所有分数

[复制链接]
发表于 2015-4-23 23:43:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 欧拉计划 于 2015-4-23 23:45 编辑
Digit cancelling fractions

The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.

We shall consider fractions like, 30/50 = 3/5, to be trivial examples.

There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.

If the product of these four fractions is given in its lowest common terms, find the value of the denominator.

题目:

分数 49/98 是一个奇怪的分数:当一个菜鸟数学家试图对其进行简化时,他可能会错误地可以认为通过将分子和分母上的

9 同时去除得到 49/98 = 4/8。但他得到的结果却是正确的。

我们将 30/50 = 3/5 这样的分数作为普通个例。

一共有四个这样的非普通分数,其值小于 1,并且包括分子和分母都包括 2 位数。

如果将这四个分数的乘积约分到最简式,分母是多少?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-29 17:03:18 | 显示全部楼层
本帖最后由 迷雾少年 于 2016-8-29 17:07 编辑

16/64
26/65
49/98
19/95
  1. /输入2个数字去除相同的数字 返回相除结果
  2. float calc2(int a,int b)
  3. {
  4.         float a1 = a%10;      //a的个位数
  5.         float a2 = (a/10)%10; //a的十位数

  6.         float b1 = b%10;      //b的个位数
  7.         float b2 = (b/10)%10; //b的十位数
  8.         if(a1==b1) return a2/b2;
  9.         else if(a1==b2)
  10.         {
  11.                 return a2/b1;
  12.         }
  13.         else if(a2==b1)return a1/b2;
  14.         return 0;
  15. }
  16. int main()
  17. {
  18.        
  19.         for (float fenmu=1;fenmu<100;fenmu++)
  20.         {
  21.                 for (float fenzi=1;fenzi<fenmu;fenzi++)
  22.                 {
  23.                         if(calc2(fenzi,fenmu) == fenzi/fenmu )
  24.                         {
  25.                                 cout<<fenzi<<"/"<<fenmu<<endl;
  26.                         }
  27.                 }
  28.         }
  29.         return 0;
  30.        
  31. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-9-2 16:37:52 | 显示全部楼层
  1. list1 = []
  2. count_i=1
  3. count_j=1
  4. for i in range(10,100):
  5.       for j in range(10,100):
  6.             if i < j:
  7.                   str_1 = str(i)
  8.                   if str_1[0]!=str_1[1] and str_1[1]!='0':
  9.                         for each in str(i):
  10.                               if each in str(j):
  11.                                     temp = int(str(i).replace(each,'',1))
  12.                                     tmp = int(str(j).replace(each,'',1))
  13.                                     if (tmp!=0) and (temp/tmp == i/j) :
  14.                                           count_i *=i
  15.                                           count_j *=j
  16. list2 = []
  17. def gcd(x,y):
  18.       if y:
  19.             return gcd(y,x%y)
  20.       else:
  21.             return x
  22. x = gcd(count_i,count_j)
  23. print(int(count_j/x))
复制代码

结果是100
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-1-13 22:03:16 | 显示全部楼层
  1. # encoding:utf-8
  2. # pandigital 之和
  3. from time import time
  4. def isUc(m, n):
  5.     if len(str(m).strip(str(n))) == len(str(m)):
  6.         return False
  7.     m1 = str(m).strip(str(n))
  8.     n1 = str(n).strip(str(m))
  9.     if not m1 or not n1:
  10.         return False
  11.     if int(m1) / int(n1) == m / n:
  12.         return True
  13.     return False
  14. def euler033():
  15.     l_result = []
  16.     for i in range(11, 100):
  17.         if i % 10 == 0 or i % 11 == 0:
  18.             continue
  19.         for j in range(11, i):
  20.             if j % 10 == 0 or j % 11 == 0:
  21.                 continue
  22.             if isUc(j, i):
  23.                 print(i, j)
  24.                 l_result.append(i)
  25.     print(sum(l_result))           
  26. if __name__ == '__main__':
  27.     start = time()
  28.     euler033()
  29.     print('cost %.6f sec' % (time() - start))
复制代码


64 16
65 26
95 19
98 49
322
cost 0.006003 sec
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-6-5 00:47:38 | 显示全部楼层
此代码使用matlab编程
Problem33所用时间为1.2507秒
Problem33的答案为100
  1. % Problem33.m
  2. % 最后编辑时间:17-06-05 0:18
  3. % 问题:求所有非正常约分的分数的乘积的分母
  4. tic

  5. Up = 1;
  6. Down = 1;
  7. for aa = 99 : -1 : 12
  8.     Deno = aa;
  9.     for bb = Deno - 1: -1: 11
  10.         Elem = bb;
  11.         NewDeno = num2str(Deno);
  12.         OtherDeno = str2double(NewDeno(2));

  13.         NewElem = num2str(Elem);
  14.         OtherElem = str2double(NewElem(1));
  15.         if OtherElem / OtherDeno == Elem / Deno ...
  16.                 && strcmp(NewDeno(1),NewDeno(2)) == 0 && strcmp(NewElem(1),NewElem(2)) == 0 && strcmp(NewDeno(1),NewElem(2)) == 1
  17.             Up = Up * Elem;
  18.             Down = Down *Deno;
  19.         end
  20.     end
  21. end
  22. Gcd = gcd(Up,Down);
  23. Output = Down / Gcd;
  24. toc
  25. disp('此代码使用matlab编程')
  26. disp(['Problem33所用时间为',num2str(toc),'秒'])
  27. disp(['Problem33的答案为',num2str(Output)])
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

匿名鱼油  发表于 2018-4-17 22:32:19

去除普通个例
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具

发表于 2018-9-10 20:06:02 | 显示全部楼层
本帖最后由 永恒的蓝色梦想 于 2020-7-2 18:34 编辑
  1. c = []
  2. for i in range(10, 100):
  3.     c.append(i)

  4. d = []
  5. for i in range(10, 100):
  6.     d.append(i)

  7. a = []
  8. for item in c:
  9.     # print(item)
  10.     for item1 in str(item):
  11.         a.append(item1)  # 最新的数据都是-1,-2

  12. b = []
  13. for item in d:
  14.     # print(item)
  15.     for item1 in str(item):
  16.         b.append(item1)

  17. for i in range(0, 180, 2):
  18.     for j in range(0, 180, 2):
  19.         A = int(a[i])
  20.         B = int(a[i + 1])
  21.         C = int(b[j])
  22.         D = int(b[j+1])
  23.         if D == 0 or C == 0:
  24.             continue

  25.         if (A*10 + B) != (C*10 + D):
  26.             if A == D:
  27.                 if (A*10 + B) / ((C*10 + D)*1.0) == B/(C*1.0):
  28.                     print((A*10 + B), (C*10 + D))
  29.                     print('-------1-------')
  30.             if A == C:
  31.                 if (A*10 + B) / ((C*10 + D)*1.0) == B/(D*1.0):
  32.                     print((A*10 + B), (C*10 + D))
  33.                     print('-------2-------')
  34.             if B == C:
  35.                 if (A*10 + B) / ((C*10 + D)*1.0) == A/(D*1.0):
  36.                     print((A*10 + B), (C*10 + D))
  37.                     print('-------3-------')
  38.             if B == D:
  39.                 if (A*10 + B)/((C*10 + D)*1.0) == A/(C*1.0):
  40.                     print((A*10 + B), (C*10 + D))
  41.                     print('-------4-------')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-3-26 16:20:33 | 显示全部楼层
['16/64', '19/95', '26/65', '49/98']
322
cost 0.000000 sec
  1. from time import time

  2. def EP033():
  3.     list1 = []
  4.     for a in range(10, 100):
  5.         for b in range(a + 1, 100):
  6.             if (a // 10 == b // 10 or a // 10 == b % 10 or a % 10 == b // 10 or a % 10 == b % 10) and (
  7.                     a % 10 != 0 and b % 10 != 0):
  8.                 list1.append(str(a // 10) + str(a % 10) + "/" + str(b // 10) + str(b % 10))

  9.     list2 = []

  10.     for each in list1:
  11.         if each[0] == each[3]:
  12.             list2.append(each[1:3] + each[4])
  13.         elif each[0] == each[4]:
  14.             list2.append(each[1:4])
  15.         elif each[1] == each[3]:
  16.             list2.append(each[0] + each[4])
  17.         else:
  18.             list2.append(each[0] + each[3])

  19.     value_list1 = []
  20.     value_list2 = []
  21.     for each1 in list1:
  22.         value_list1.append(round(int(each1[:2]) / int(each1[3:]), 3))

  23.     for each2 in list2:
  24.         value_list2.append(round(int(each2[0]) / int(each2[-1]), 3))

  25.     list3 = []
  26.     for i in range(len(list1)):
  27.         if value_list1[i] == value_list2[i]:
  28.             list3.append(list1[i])

  29.     print(list3)
  30.     sum = 0
  31.     for each3 in list3:
  32.         sum += int(each3[3:])
  33.     print(sum)

  34. if __name__ == '__main__':
  35.     start = time()
  36.     EP033()
  37.     print('cost %.6f sec' % (time() - start)
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-13 13:11:52 | 显示全部楼层
分子分母:[(49, 98), (19, 95), (16, 64), (26, 65)]
化简分母:[100.0]
用时:0.156001秒
  1. import functools
  2. import time


  3. def get_strange_list():
  4.     result = []
  5.     s_list = []
  6.     # x > y
  7.     for x in range(11, 100):
  8.         for y in range(11, x):
  9.             if not x % 10 and not y % 10:
  10.                 continue
  11.             for each_letter in str(x):
  12.                 if each_letter in str(y) \
  13.                         and x != y \
  14.                         and int(str(y).replace(each_letter, '', 1)) != 0 \
  15.                         and int(str(x).replace(each_letter, '', 1))/int(str(y).replace(each_letter, '', 1)) == x/y:
  16.                     s_list.append((y, x))
  17.     s_list = list(set(s_list))

  18.     # 求 x,y (x<y) 的最大公约数
  19.     x = functools.reduce(lambda x1, x2: x1*x2, [each[1] for each in s_list])
  20.     y = functools.reduce(lambda x1, x2: x1 * x2, [each[0] for each in s_list])
  21.     tmp = y
  22.     while True:
  23.         if not y % tmp and not x % tmp:
  24.             result.append(x/tmp)
  25.             break
  26.         else:
  27.             tmp -= 1
  28.     return s_list, result
  29. strange_list, result = get_strange_list()

  30. print("分子分母:{}\n化简分母:{}\n用时:{}秒".format(strange_list, result, time.process_time()))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-29 19:26:27 | 显示全部楼层
C++ 0ms
  1. #include<iostream>
  2. using namespace std;


  3. int gcd(int a, int b) {
  4.     int c;
  5.     while (b) {
  6.         c = a % b;
  7.         a = b;
  8.         b = c;
  9.     }
  10.     return a;
  11. }


  12. bool judge(int a, int b) {
  13.     int c = a / 10, d = b % 10, e, f;
  14.     return a % 10 == b / 10 && a / (e = gcd(a, b)) == c / (f = gcd(c, d)) && b / e == d / f;
  15. }


  16. int main() {
  17.     int nume = 1, deno = 1, i, j;

  18.     for (i = 10; i < 100; i++) {
  19.         for (j = i + 1; j < 100; j++) {
  20.             if (judge(i, j)) {
  21.                 nume *= i;
  22.                 deno *= j;
  23.             }
  24.         }
  25.     }

  26.     cout << deno / gcd(nume, deno) << endl;
  27.     return 0;
  28. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-13 17:27:44 | 显示全部楼层
100

Process returned 0 (0x0)   execution time : 0.029 s
Press any key to continue.
暴力枚举,同时推得一些性质
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;

  4. bool judge(int a,int b,int c,int d){
  5.   return a * b == c * d;
  6. }

  7. int gcd(int x,int y){
  8.   int r;
  9.   while(y){
  10.     r = x % y;
  11.     x = y;
  12.     y = r;
  13.   }
  14.   return x;
  15. }

  16. int main(){
  17.   int numertr = 1,divisr = 1;//初始化分子分母

  18.   for (int a1 = 1;a1 < 10;a1++){
  19.     for (int a2 = a1+1;a2 < 10;a2++){
  20.       int a = a1 * 10 + a2;
  21.       int b;

  22.       for (int a3 = a1+1;a3 < 10;a3++){
  23.         b = a3 * 10 + a1;
  24.         if (judge(a,a3,b,a2)) { numertr *= a2; divisr *= a3; }
  25.       }

  26.       for (int a4 = 1;a4 < 10;a4++){
  27.         b = a2 * 10 + a4;
  28.         if (judge(a,a4,b,a1)) { numertr *= a1; divisr *= a4; }
  29.       }
  30.     }
  31.   }
  32.   divisr /= gcd(numertr,divisr);
  33.   cout << divisr << endl;
  34.   return 0;
  35. }
复制代码

点评

我很赞同!: 5.0
我很赞同!: 5
分母的英文是 denominator 哦  发表于 2020-8-13 18:31

评分

参与人数 1荣誉 +3 鱼币 +3 贡献 +3 收起 理由
永恒的蓝色梦想 + 3 + 3 + 3

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-23 09:53:52 | 显示全部楼层
  1. start = time.time()

  2. for a in range(10,50):
  3.     if a % 10 != 0:
  4.         for b in range(10,100):
  5.             if b % 10 != 0 and a != b :
  6.                 check = 0
  7.                 sa = list(str(a))
  8.                 sb = list(str(b))
  9.                 for each in sa:
  10.                     if each in sb:
  11.                         same = each
  12.                         check += 1
  13.                 if check == 1:
  14.                     sa.remove(same)
  15.                     sb.remove(same)
  16.                     if a / b == int(sa[0]) / int(sb[0]):
  17.                             print("%d / %d" %(a,b))

  18. end = time.time()
  19. print("共用时%f秒" %(end - start))
复制代码


16 / 64
19 / 95
26 / 65
49 / 98
共用时0.004488秒
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-23 10:17:11 | 显示全部楼层
  1. start = time.time()

  2. numer = 1
  3. dino = 1
  4. for a in range(10,50):
  5.     if a % 10 != 0:
  6.         for b in range(10,100):
  7.             if b % 10 != 0 and a != b :
  8.                 check = 0
  9.                 sa = list(str(a))
  10.                 sb = list(str(b))
  11.                 for each in sa:
  12.                     if each in sb:
  13.                         same = each
  14.                         check += 1
  15.                 if check == 1:
  16.                     sa.remove(same)
  17.                     sb.remove(same)
  18.                     if a / b == int(sa[0]) / int(sb[0]):
  19.                             numer *= a
  20.                             dino *= b
  21.                             print("%d / %d" %(a,b))

  22. print("约分后分母为: %d" %(int(dino/numer)))


  23. end = time.time()
  24. print("共用时%f秒" %(end - start))
复制代码

16 / 64
19 / 95
26 / 65
49 / 98
约分后分母为: 100
共用时0.003944秒
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-14 22:39:10 | 显示全部楼层
  1. #include <stdio.h>

  2. int MaxDiv(int, int);
  3. int MaxDiv(int m, int n)
  4. {
  5.         if (m == 0 || n == 0)
  6.         {
  7.                 printf("有数字为0\n");
  8.                 return -1;
  9.         }
  10.         int max, min, temp;
  11.         max = m > n ? m : n;
  12.         min = m < n ? m : n;
  13.         while (max % min)
  14.         {
  15.                 temp = max % min;
  16.                 max = min;
  17.                 min = temp;
  18.         }
  19.         return min;
  20. }


  21. main()
  22. {
  23.         int i, j, a, b, c, d, num = 1, den = 1;
  24.         double x, y;

  25.         for (i = 11; i < 100; i++)
  26.         {
  27.                 for (j = i + 1; j < 100; j++)
  28.                 {
  29.                         a = i % 10;
  30.                         b = i / 10;
  31.                         c = j % 10;
  32.                         d = j / 10;
  33.                         if (a == 0 || b == 0 || c == 0 || d == 0)
  34.                         {
  35.                                 continue;
  36.                         }

  37.                         if (a == c)
  38.                         {
  39.                                 x = (double)b / d;
  40.                                 y = (double)i / j;
  41.                                 if (x == y)
  42.                                 {
  43.                                         num *= i;
  44.                                         den *= j;
  45.                                         printf("%d / %d\n", i, j);
  46.                                 }
  47.                         }
  48.                         if (a == d)
  49.                         {
  50.                                 x = (double)b / c;
  51.                                 y = (double)i / j;
  52.                                 if (x == y)
  53.                                 {
  54.                                         num *= i;
  55.                                         den *= j;
  56.                                         printf("%d / %d\n", i, j);
  57.                                 }
  58.                         }
  59.                         if (b == c)
  60.                         {
  61.                                 x = (double)a / d;
  62.                                 y = (double)i / j;
  63.                                 if (x == y)
  64.                                 {
  65.                                         num *= i;
  66.                                         den *= j;
  67.                                         printf("%d / %d\n", i, j);
  68.                                 }
  69.                         }
  70.                         if (b == d)
  71.                         {
  72.                                 x = (double)a / c;
  73.                                 y = (double)i / j;
  74.                                 if (x == y)
  75.                                 {
  76.                                         num *= i;
  77.                                         den *= j;
  78.                                         printf("%d / %d\n", i, j);
  79.                                 }
  80.                         }
  81.                 }
  82.         }
  83.         i = MaxDiv(num, den);
  84.         printf("%d\n", den / i);

  85. }
复制代码


答案为:
16 / 64
19 / 95
26 / 65
49 / 98

100
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-18 20:24:16 | 显示全部楼层
#找出具有一种奇怪约分性质的所有分数
from time import *
def deal_string(x, y):
    if str(x)[0] == str(y)[0]:
        return int(str(x)[1]) / int(str(y)[1])
    elif str(x)[0] == str(y)[1]:
        return int(str(x)[1]) / int(str(y)[0])
    elif str(x)[1] == str(y)[0]:
        return int(str(x)[0]) / int(str(y)[1])
    elif str(x)[1] == str(y)[1]:
        return int(str(x)[0]) / int(str(y)[0])

def get_strange_num():
    strange_num = []
    for a in range(10, 100):
        for b in range(10, 100):
            if a % 10 != 0 and b % 10 != 0:
                if a < b and (a / b) == deal_string(a, b):
                    strange_num.append('%s/%s' % (a, b))
    return strange_num
start = time()
result = get_strange_num()

#计算
fenzi = 1
fenmu = 1
for each in result:
    fenzi *= int(each[0] + each[1])
    fenmu *= int(each[3] + each[4])
end = time()
print(fenmu//fenzi)
print("用时:%.9f秒" % (end - start))
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-1-3 15:17:56 | 显示全部楼层
  1. /*
  2. 答案:100
  3. 耗时:0.0000015秒
  4. */
  5. #include <iostream>
  6. #include <algorithm>
  7. using namespace std;

  8. int gcd(int x, int y)
  9. {
  10.   if (y == 0)
  11.     return x;
  12.   int z = x % y;
  13.   while (z != 0)
  14.   {
  15.     x = y;
  16.     y = z;
  17.     z = x % y;
  18.   }
  19.   return y;
  20. }

  21. int main(void)
  22. {
  23.   int n = 1, d = 1;//分别保存特殊分数之积的分子和分母
  24.   //这样的特殊分数只牵涉到三个数,我们分别枚举它们
  25.   for (int a = 1; a <= 9; ++a)
  26.   {
  27.     for (int b = 0; b <= 9; ++b)
  28.     {
  29.       for (int c = 1; c <= 9; ++c)
  30.       {
  31.         int x = 10 * a + b;//构造分子
  32.         int y = 10 * b + c;//构造分母
  33.         if (x == 0 || y == 0)
  34.           continue;
  35.         if (x < y)//检查第一个要求
  36.         {
  37.           if (x * c == y * a)//检查第二个要求
  38.           {
  39.             //保存结果
  40.             n *= a;
  41.             d *= c;
  42.           }
  43.         }
  44.         else
  45.         {
  46.           swap(x, y);//相同的数字位置调换一下
  47.           if (x < y)//检查第一个要求
  48.           {
  49.             if (a * x == c * y)//检查第二个要求
  50.             {
  51.               //保存结果
  52.               n *= c;
  53.               d *= a;
  54.             }
  55.           }
  56.         }
  57.       }
  58.     }
  59.   }
  60.   int p = gcd(n, d);
  61.   d /= p;//约简分数
  62.   cout << d << endl;//输出分母
  63.   return 0;
  64. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-2-15 14:38:09 | 显示全部楼层
这个应该会快一些,但是计算量实在是太小了。重复10000测时间
100
Time:0.17248201370239258s
  1. """
  2. (10i+j)/(10j+k)=i/k  ==>  (9i+j)k=10ij
  3. (10i+j)/(10k+i)=j/k  ==>  (9k+i)j=10ik

  4. (9i+j)k=10ij ==> k=10ij/(9i+j)
  5. """
  6. import time
  7. st=time.time()
  8. def get():
  9.     # a=[]
  10.     b=1
  11.     c=1
  12.     for i in range(1,10):
  13.         for j in range(10):
  14.             if j==i:
  15.                 continue
  16.             if not 10*i*j%(9*i+j)==0:
  17.                 continue
  18.             k=10*i*j//(9*i+j)
  19.             if i==k or j==k:
  20.                 continue
  21.             # a.append((min(i,k),j,max(i,k)))
  22.             b,c=b*min(i,k),c*max(i,k)
  23.     bb,cc=b,c
  24.     while bb>0 and cc>0:
  25.         if bb<cc:
  26.             cc=cc%bb
  27.         else:
  28.             bb=bb%cc
  29.     return c//max(bb,cc)
  30. for i in range(10000):
  31.     get()
  32. print(get())
  33. print('Time:{}s'.format(time.time()-st))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-10-12 15:35:30 | 显示全部楼层
$ time ./main-v2
100

real        0m0.001s
user        0m0.000s
sys        0m0.001s
  1. fn gcd(x:usize,y:usize) -> usize {
  2.     let (mut b, mut l) = (x, y);
  3.     if b < l {
  4.         (b,l) = (l,b)
  5.     }
  6.     while l != 0 {
  7.         b %= l;
  8.         (b,l) = (l,b)
  9.     }
  10.     b
  11. }
  12. fn bits(x: usize) -> usize {
  13.     let mut x = x;
  14.     let mut ans = 0;
  15.     while x != 0 && x % 10 != 0 {
  16.         ans ^= 1 << (x % 10 - 1);
  17.         x /= 10;
  18.     }
  19.     ans
  20. }

  21. fn main() {
  22.     let mut v = vec![];
  23.     for i in 10..99 {
  24.         for j in (i + 1)..=99 {
  25.             let t = bits(i)&bits(j);
  26.             if t.count_ones() != 1 {continue;}
  27.             let ri = (bits(i)^t).trailing_zeros() as usize + 1;
  28.             let rj = (bits(j)^t).trailing_zeros() as usize + 1;
  29.             if ri * j == rj * i {
  30.                 v.push((ri, rj));
  31.             }
  32.         }
  33.     }
  34.     let i = v.iter().map(|x| x.0).product::<usize>();
  35.     let j = v.iter().map(|x| x.1).product::<usize>();
  36.     println!("{}", j / gcd(i, j));
  37. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-20 01:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表