用matlab求2到999之间同时满足下列两条件的自然数:(1)该数各位数字之和是奇数;(2)该数是素数.

1个回答

  • clear;

    clc;

    index = 1;

    for ii = 2:999;

    if(mod(sum(num2str(ii)-'0'), 2) && isprime(ii))

    out(index) = ii;

    index = index+1;

    end

    end

    out

    结果:

    3, 5, 7, 23, 29, 41, 43, 47, 61, 67, 83, 89, 113, 131, 137, 139, 151, 157, 173, 179, 191, 193, 197, 199, 223, 227, 229, 241, 263, 269, 281, 283, 311, 313, 317, 331, 337, 353, 359, 373, 379, 397, 401, 409, 421, 443, 449, 461, 463, 467, 487, 557, 571, 577, 593, 599, 601, 607, 641, 643, 647, 661, 683, 719, 733, 739, 751, 757, 773, 797, 809, 821, 823, 827, 829, 863, 881, 883, 887, 911, 919, 937, 953, 971, 977, 991, 997