matlab 欧拉计划 33
程序员文章站
2022-03-31 20:47:04
...
problem 33
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.
思路
(我感觉这个问题不太好理解,于是查了一些资料,然后理出一种思路。 感谢各位大佬分享经验。)
- 要求:找出四个非平凡数,找出它们最大公因数最简化后(也就是相乘得到的最简分数形式)的分母。
- 经观察可得,这种非平凡数要求分子个位数与分母十位数相同,同时将对应位的数字略去后得到的分数与原分数结果相同。(我觉得很神奇)
程序
clc;clear all;
format rat;
t=[];t1=1;
for i=10:99
for j=10:99
ii=num2str(i); i1=str2num(ii(1)); i2=str2num(ii(2));
jj=num2str(j); j2=str2num(jj(2)); j1=str2num(jj(1));
if i2==j1
if (i/j)==(i1/j2)&&(i/j)<1
t=[t ;i j];t1=t1*(i/j);
end
end
end
end
上一篇: 欧拉计划matlab实现:问题1
下一篇: Matlab中的元胞数组