问题描述:
The fraction49/98is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/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.
思路:
1.找到1位数的所有分数
2.找到两位数的分数,把分子分母有重叠的部分去掉,如果相等,存入数组
3.对比两个数组的结果,找到相同的
javascript实现:
(function(){
var dig = function (m,n){
var arr = new Array();
for(j=m+1;j<n;j++){
for(var i = m;i < j ;i++){
arr.push({i:i,j:j});
}
}
return arr;
}
var filter = function(arr){
var ret =new Array();
for(var i = 0; i < arr.length ; i++){
var strN = arr[i].i.toString();
var strM = arr[i].j.toString();
if(strN.indexOf(strM[0]) != -1&&strM[0]!='0'){
if(strN[0] == strM[0] && parseInt(strN)/parseInt(strM) == parseInt(strN[1]) / parseInt(strM[1])){ret.push({i:strN[1],j:strM[1],ori:strN+"/"+strM});}
else if(strN[1] == strM[0] && parseInt(strN)/parseInt(strM) == parseInt(strN[0]) / parseInt(strM[1])){ret.push({i:strN[0],j:strM[1],ori:strN+"/"+strM});}
}
else if(strN.indexOf(strM[1]) != -1&&strM[1]!='0'){
if(strN[0] == strM[1]&& parseInt(strN)/parseInt(strM) == parseInt(strN[1]) / parseInt(strM[0])){ret.push({i:strN[1],j:strM[0],ori:strN+"/"+strM});}
else if (strN[0] == strM[1] && parseInt(strN)/parseInt(strM) == parseInt(strN[1]) / parseInt(strM[0])){ret.push({i:strN[1],j:strM[0],ori:strN+"/"+strM});}
}
}
return ret;
}
var ret1 = dig(1,10);
var ret2= filter(dig(10,100));
console.log(ret2);
for(var j = 0 ;j < ret1.length ;j++){
for(var i = 0;i < ret2.length; i++){
//console.log(ret2[i].i + "/" + ret2[i].j + " = " + ret1[j].i + "/" + ret1[j].j);
if(parseInt(ret2[i].i) / parseInt(ret2[i].j) == parseInt(ret1[j].i) / parseInt(ret1[j].j)){
console.log(ret2[i].ori + " = " + ret1[j].i + "/" + ret1[j].j);
}
}
}
})();
分享到:
相关推荐
三下Unit 8 The Ruler Is Long课时练习题及答案精选.doc
ruler相关;ruler相关;ruler相关;ruler相关;ruler相关;
WonderWebware Screen Ruler Pro 是 WonderWebware 公司出品的一个功能非常强大的屏幕尺软件,用来测量屏幕上任意两点之间的距离,可以在设计网页时用它测量网页上的元素来确定位置和大小,此版本为专业版. 标尺的单位...
简单好用的屏幕尺子aruler,1:1比例,Windows下简单实用。
e-ruler 网页测量工具 可以测量两点之间距离,多点之间距离,测量角度,显示起点和终点的坐标值
Privacy Friendly Ruler Privacy Friendly Ruler turns the phone screen into a ruler for quick measurments on the go. This app is optimized regarding the user's privacy. It doesn't use any tracking ...
PageRuler插件,测量网页长度,宽度
E-Ruler E-尺是一个用来测量的工具软件,可以用来测量屏幕上两点或多点的距离和角度,特别适合从事网页或美工工作的您
直尺,尺子,小工具,Ruler,尺子小程序,实用,屏幕尺子
三下Unit 8 The Ruler Is Long课时练习题及答案4精选.doc
三下Unit 8 The Ruler Is Long课时练习题及答案3精选.doc
三下Unit 8 The Ruler Is Long课时练习题及答案2精选.doc
slide-ruler二次封装后的组件
年Unit 8 The ruler is long课堂练习题及答案陕旅版精选.doc
Android 8.0+ 并安装ARCore ARuler Pro v1.3.4_build_48 (汉化_繁体) AR Plan 3D Ruler V2.0 (3D需求组件.可不安装)
年Unit 8 The ruler is long课堂练习题及答案陕旅版3精选.doc
年Unit 8 The ruler is long课堂练习题及答案陕旅版4精选.doc
年Unit 8 The ruler is long课堂练习题及答案陕旅版2精选.doc
Java例程,创建一个Ruler,使用Eclipse环境
《细说PHP》课程配套用的尺子,很好用。 《细说PHP》课程配套用的尺子,很好用。 《细说PHP》课程配套用的尺子,很好用。