0
$\begingroup$

Let n be the integer shown below:

n = 142065190756865870282488068105667182577501738882057884851974445654\
3423237742166396721779311436580070305999267257391443148780739279119880\
6036362837818906515298335482078702168477375932413656083756056968587479\
3126870900658037035232621234336490924847626041243376077191947718333766\
2139781422597901111260689303906160406976537383552880685721245542814240\
4381640394269606051500

Given questions:

  1. In the prime factorization of $n$, how many prime factors have an odd exponent?

  2. Let $a_i$ be the $i$th prime factor of $n$, ordered from least to greatest (so $a_1=2$, $a_2=3$, $a_9=29$, etc.). Evaluate the sum:

$-a_1+a_2-a_3+...+(-1)^m * a_m$ (**)

where $a_m$ is the greatest prime factor of $n$. (For example, if the question was about $n=84=2\times2\times3\times7$ the answer would be $-2+3-7=-6$).

1)

pf = FactorInteger[n];  
odd = Cases[pf, {x_, y_} /; OddQ[y] :> y]; 
Cases[pf, {x_, y_} /;  OddQ[y] :> HoldForm[x^y]]
Counts[odd]
Total[%] 

2) I think it's asking to calculate the alternating sum of all unique prime factors of $n$ but I'm having trouble how it should be approached when it comes to iterating the function (**).

$\endgroup$
1
  • 1
    $\begingroup$ The subject header is, ironically, quite vague. $\endgroup$ Commented Jan 29, 2018 at 15:41

1 Answer 1

1
$\begingroup$

Your interpretation of part 1 looks fine, though it could be much shorter. Since we know that FactorInteger returns {x,y} pairs where y is the exponent, then we can do this:

a = FactorInteger[n];
Count[a, {x_,y_?OddQ}]

For part two, you can use Sum directly over the length of the list:

a = FactorInteger[n];
Sum[(-1)^i a[[i, 1]], {i, 1, Length[a]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.