Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \def\makeatletter{\catcode `\@11\relax}
- \def\makeatother{\catcode `\@12\relax}
- \makeatletter
- \newif\ifdivisible
- \newcount\testMod@n
- \def\testMod#1#2{% sets divisible = [#1 mod #2 == 0]
- \testMod@n=#1%
- \divide\testMod@n by#2%
- \multiply\testMod@n by#2%
- \ifnum#1=\testMod@n%
- \divisibletrue%
- \else%
- \divisiblefalse%
- \fi%
- }
- \newcount\divisorpower
- \newcount\getDivisorPower@n
- \def\getDivisorPower#1#2{% sets divisorpower = {max a such that #2^a divides #1} and getDivisorPower@n = #1/#2^a
- \getDivisorPower@n=#1%
- \divisorpower=0%
- \testMod{\getDivisorPower@n}{#2}%
- \loop\ifdivisible%
- \advance\divisorpower by1%
- \divide\getDivisorPower@n by#2%
- \testMod{\getDivisorPower@n}{#2}%
- \repeat%
- }
- \newcount\numberpower
- \newcount\getNumberPower@pow
- \def\getNumberPower#1#2{% sets numberpower = #1^#2
- \numberpower=1
- \getNumberPower@pow=#2
- \loop\ifnum\getNumberPower@pow>0
- \multiply\numberpower by#1
- \advance\getNumberPower@pow by-1
- \repeat
- }
- \newif\ifcanonical@more
- \newcount\canonical@n
- \newcount\canonical@i
- \newcount\canonical@sqri
- \def\canonical#1#2{% runs #2{p}{a} for each p^a such that divides #1 and p^{a+1} does not divide
- \canonical@n=#1%
- \canonical@i=2%
- %
- \ifnum\canonical@n<4
- \canonical@morefalse%
- \else
- \canonical@moretrue%
- \fi%
- %
- \loop\ifcanonical@more%
- {%
- \getDivisorPower{\canonical@n}{\canonical@i}%
- \ifnum\divisorpower>0%
- #2{\number\canonical@i}{\number\divisorpower}%
- \global\canonical@n=\getDivisorPower@n%
- \fi%
- }%
- %
- \ifodd\canonical@i%
- \advance\canonical@i by2%
- \else%
- \advance\canonical@i by1%
- \fi%
- \canonical@sqri=\canonical@i%
- \multiply\canonical@sqri by\canonical@sqri%
- %
- \ifnum\canonical@n<2
- \canonical@morefalse%
- \fi%
- \ifnum\canonical@n<\canonical@sqri%
- \canonical@morefalse%
- \fi%
- \repeat%
- %
- \ifnum\canonical@n>1
- #2{\number\canonical@n}{1}%
- \fi
- }
- \def\printCanonHelper#1#2{\cdot#1^#2}
- \def\printCanon#1{$$ #1 = 1\canonical{#1}{\printCanonHelper} $$}
- \newcount\eulerPhi@v
- \newcount\eulerPhi@p
- \newcount\eulerPhi@a
- \def\eulerPhiHelper#1#2{
- \eulerPhi@p=#1
- \eulerPhi@a=#2
- \advance\eulerPhi@a by-1
- \getNumberPower{\eulerPhi@p}{\eulerPhi@a}
- \advance\eulerPhi@p by-1
- \multiply\numberpower by\eulerPhi@p
- \global\multiply\eulerPhi@v by\numberpower
- }
- \def\eulerPhi#1{
- \eulerPhi@v=1
- \canonical{#1}{\eulerPhiHelper}
- $$ \varphi(#1)= \number\eulerPhi@v $$
- }
- \makeatother
- \printCanon{1546275796}
- \eulerPhi{1546275796}
- \end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement