-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem050_c.m
More file actions
43 lines (37 loc) · 847 Bytes
/
problem050_c.m
File metadata and controls
43 lines (37 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function problem050_c(N)
tic
p=primes_to_n(N);
num=length(p);
pc = zeros(1,num);
%this part of code is to write algo for existing function cumsum
k =0;
for j = 1:num
k = k + p(1,j);
pc(1,j) = k;
end
%pc=cumsum(p);
toc
tic
bestd=0;
for i=1:num
s=0;
for j=(i+bestd):num
s=pc(j)-pc(i);
if s>p(num)
break;
end
m=[];
m=find(p==s);
if length(m)==1
d=j-i;
if d>bestd
%besti=i;
%bestj=j;
bestd=d;
bestm=m;
end
end
end
end
toc
p(bestm)