- 积分
- 46
- 注册时间
- 2007-4-28
- 仿真币
-
- 最后登录
- 1970-1-1
|
本帖最后由 qibbxxt 于 2010-9-27 15:18 编辑
原问题来自:http://forum.simwe.com/viewthread.php?tid=911960&extra=page%3D1%26amp%3Bfilter%3Dtype%26amp%3Btypeid%3D508
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
What 12-digit number do you form by concatenating the three terms in this sequence?
1487, 4817, 8147这三个数有如下特征:都是素数;由相同的数位组成(1,4,7,8);三者构成等差数列。
已知在四位数中仍然有一组与此类似的等差数列,试找出来这三个数,并且按照这三个数字大小递增的顺序写出这十二个位数来
我用matlab 来实现,本来已经答复过,但是还是觉得放在这里大家一起讨论,会好一些- function dd=ex092603
- tic
- b=3:-1:0;
- a=primes(10^length(b)-1);
- a=a(a>10^(length(b)-1));
- [e,f,g]=unique(sort(mod(floor(bsxfun(@rdivide,repmat(a',1,length(b)),10.^b)),10),2),'rows');
- pc=accumarray(g,a',[],@(x){x});
- dd=cell2mat(cellfun(@isContinuePrimes,pc,'UniformOutput',false));
- toc
- function y=isContinuePrimes(x)
- y=[];
- if length(x)>2
- y0=nchoosek(x,3);
- y1=(max(y0,[],2)+min(y0,[],2))/2;
- y2=y1==mean(y0,2);
- if any(y2)
- y=y0(y2,:);
- end
- end
复制代码-
- Elapsed time is 0.071698 seconds.
- ans =
- 1487 4817 8147
- 6299 9629 2969
复制代码
|
评分
-
1
查看全部评分
-
|