2017二人转总动员正戏:恳请各位达人帮才鸟笑地解决一个非常简单的matlab编程问题

来源:百度文库 编辑:高考问答 时间:2024/05/09 13:08:53
求[2,999]中同时满足下列条件的数:
(1)该数各位数字之合为奇数
(2)该数是素数

temp = [];
result = [];
for i =2:999

ii = num2str(i);
k=0;
for j = 1:length(ii)
k = k + str2num(ii(j));
end

if (~any(mod(i,temp)==0)) & (mod(k,2)==1)
result = [result i];
end
temp = [temp i];
end

result =

Columns 1 through 13

3 5 7 23 29 41 43 47 61 67 83 89 113

Columns 14 through 26

131 137 139 151 157 173 179 191 193 197 199 223 227

Columns 27 through 39

229 241 263 269 281 283 311 313 317 331 337 353 359

Columns 40 through 52

373 379 397 401 409 421 443 449 461 463 467 487 557

Columns 53 through 65

571 577 593 599 601 607 641 643 647 661 683 719 733

Columns 66 through 78

739 751 757 773 797 809 821 823 827 829 863 881 883

Columns 79 through 87

887 911 919 937 953 971 977 991 997

>> fun=@(x) mod(sum(mod(x,10)+mod(floor(x/10),10)+floor(x/100)),2);
>> p=primes(999);
>> i=blkproc(p,[1 1],fun);
>> p(i>0)