divisores.mws

PRINCÍPIO DA INCLUSÃO-EXCLUSÃO

Problema B2:

11/10/2007

 > mil := {seq(i, i=1..1000)}:

 > A_2 := mil intersect {seq(2*i, i=1..1000)}:

 > A_3 := mil intersect {seq(3*i, i=1..1000)}:

 > A_5 := mil intersect {seq(5*i, i=1..1000)}:

 > A_7 := mil intersect {seq(7*i, i=1..1000)}:

 > A_2_3 := mil intersect {seq(2*3*i, i=1..1000)}:

 > A_2_5 := mil intersect {seq(2*5*i, i=1..1000)}:

 > A_2_7 := mil intersect {seq(2*7*i, i=1..1000)}:

 > A_3_5 := mil intersect {seq(3*5*i, i=1..1000)}:

 > A_3_7 := mil intersect {seq(3*7*i, i=1..1000)}:

 > A_5_7 := mil intersect {seq(5*7*i, i=1..1000)}:

 > A_2_3_5 := mil intersect {seq(2*3*5*i, i=1..1000)}:

 > A_2_3_7 := mil intersect {seq(2*3*7*i, i=1..1000)}:

 > A_2_5_7 := mil intersect {seq(2*5*7*i, i=1..1000)}:

 > A_3_5_7 := mil intersect {seq(3*5*7*i, i=1..1000)}:

 > A_2_3_5_7 := mil intersect {seq(2*3*5*7*i, i=1..1000)}:

 > nops(A_2) + nops(A_3) + nops(A_5) + nops(A_7);

 > % - (nops(A_2_3) + nops(A_2_5) + nops(A_2_7) + nops(A_3_5) + nops(A_3_7) + nops(A_5_7));

 > % + (nops(A_2_3_5) + nops(A_2_3_7) + nops(A_2_5_7) + nops(A_3_5_7));

 > % - nops(A_2_3_5_7);

 > 1000 - %;

a1,a2,a3,a4 primos entre si

 > B2alt := proc(a_1,a_2,a_3,a_4,n::integer)

 > local numn, i, A_1, A_2, A_3, A_4,

 > A_1_2, A_1_3, A_1_4, A_2_3, A_2_4, A_3_4,

 > A_1_2_3, A_1_2_4, A_1_3_4, A_2_3_4, A_1_2_3_4;

 > numn := {seq(i, i=1..n)};

 > A_1 := numn intersect {seq(a_1*i, i=1..n)};

 > A_2 := numn intersect {seq(a_2*i, i=1..n)};

 > A_3 := numn intersect {seq(a_3*i, i=1..n)};

 > A_4 := numn intersect {seq(a_4*i, i=1..n)};

 > A_1_2 := numn intersect {seq(a_1*a_2*i, i=1..n)};

 > A_1_3 := numn intersect {seq(a_1*a_3*i, i=1..n)};

 > A_1_4 := numn intersect {seq(a_1*a_4*i, i=1..n)};

 > A_2_3 := numn intersect {seq(a_2*a_3*i, i=1..n)};

 > A_2_4 := numn intersect {seq(a_2*a_4*i, i=1..n)};

 > A_3_4 := numn intersect {seq(a_3*a_4*i, i=1..n)};

 > A_1_2_3 := numn intersect {seq(a_1*a_2*a_3*i, i=1..n)};

 > A_1_2_4 := numn intersect {seq(a_1*a_2*a_4*i, i=1..n)};

 > A_1_3_4 := numn intersect {seq(a_1*a_3*a_4*i, i=1..n)};

 > A_2_3_4 := numn intersect {seq(a_2*a_3*a_4*i, i=1..n)};

 > A_1_2_3_4 := numn intersect {seq(a_1*a_2*a_3*a_4*i, i=1..n)};

 > RETURN(n - (nops(A_1) + nops(A_2) + nops(A_3) + nops(A_4)) + nops(A_1_2) + nops(A_1_3) + nops(A_1_4) + nops(A_2_3) + nops(A_2_4) + nops(A_3_4) - (nops(A_1_2_3) + nops(A_1_2_4) + nops(A_1_3_4) + nops(A_2_3_4)) + nops(A_1_2_3_4));

 > end;

 > B2alt(2,3,5,7,1000);

 > B2 := proc(a_1,a_2,a_3,a_4,n::integer)

 > local A_1, A_2, A_3, A_4,

 > A_1_2, A_1_3, A_1_4, A_2_3, A_2_4, A_3_4,

 > A_1_2_3, A_1_2_4, A_1_3_4, A_2_3_4, A_1_2_3_4;

 > A_1 := floor(n/a_1);

 > A_2 := floor(n/a_2);

 > A_3 := floor(n/a_3);

 > A_4 := floor(n/a_4);

 > A_1_2 := floor(n/(a_1*a_2));

 > A_1_3 := floor(n/(a_1* a_3));

 > A_1_4 := floor(n/(a_1*a_4));

 > A_2_3 := floor(n/(a_2*a_3));

 > A_2_4 := floor(n/(a_2*a_4));

 > A_3_4 := floor(n/(a_3*a_4));

 > A_1_2_3 := floor(n/(a_1*a_2*a_3));

 > A_1_2_4 := floor(n/(a_1*a_2*a_4));

 > A_1_3_4 := floor(n/(a_1*a_3*a_4));

 > A_2_3_4 := floor(n/(a_2*a_3*a_4));

 > A_1_2_3_4 := floor(n/(a_1*a_2*a_3*a_4));

 > RETURN(n - (A_1 + A_2 + A_3 + A_4) + A_1_2 + A_1_3 + A_1_4 + A_2_3 + A_2_4 + A_3_4 - (A_1_2_3 + A_1_2_4 + A_1_3_4 + A_2_3_4) + A_1_2_3_4);

 > end;

 > B2(2,3,5,7,1000);

 > B2(2,3,5,7,2*3*5*7);

 > with(numtheory);

 > phi(2*3*5*7);

```Warning, the protected name order has been redefined and unprotected

```

 > phi(2*3*5*11);B2(2,3,5,11,2*3*5*11);

Número de primos entre 2 e 100 = 4+M(100)=4+B2(2,3,5,7,100)-1

 > 4+B2(2,3,5,7,100)-1;

Confirma-se:

crivo(100);

Número de primos entre 2 e 1000 = 11+M(1000)=11+B2(2,3,5,7,11,13,17,19,23,29,31,1000)-1