| Bytes | Lang | Time | Link |
|---|---|---|---|
| 049 | Arturo | 230218T203729Z | chunes |
| nan | 230219T155253Z | The Thon | |
| 092 | [Julia 1.1] | 221028T180845Z | Ashlin H |
| 010 | Pyth | 221101T185139Z | CursorCo |
| 011 | Ohm v2 | 221031T125338Z | Cliff |
| 097 | Desmos | 221031T024847Z | Aiden Ch |
| 066 | GeoGebra | 221026T060118Z | Aiden Ch |
| 012 | Japt | 221021T140524Z | Shaggy |
| 050 | Factor + math.primes.factors | 221021T100539Z | chunes |
| 040 | Charcoal | 221021T231108Z | Neil |
| 063 | Retina 0.8.2 | 221021T225005Z | Neil |
| 066 | Ruby | 221021T023047Z | Jordan |
| 015 | Brachylog | 221021T143015Z | Fatalize |
| 079 | R | 221021T124155Z | Dominic |
| 071 | JavaScript ES6 | 221021T073136Z | Arnauld |
| 007 | 05AB1E | 221021T083405Z | Kevin Cr |
| 040 | Mathematica | 221021T055339Z | hakr14 |
| 008 | Vyxal | 221021T041845Z | lyxal |
| 008 | Jelly | 221021T013058Z | naffetS |
| 019 | J | 221021T012409Z | Jonah |
| 031 | PARI/GP | 221021T013538Z | alephalp |
| 008 | Vyxal o | 221021T012624Z | naffetS |
Thunno, \$ 13 \log_{256}(96) \approx \$ 10.70 bytes
R1+Zh.S2%10dc
Attempt This Online! Port of Kevin Cruijssen's 05AB1E answer.
Thunno, \$ 16 \log_{256}(96) \approx \$ 13.17 bytes
DR1+Zh.S2%SDZKAD
Attempt This Online! Port of Steffan's Jelly answer.
Explanations
R1+Zh.S2%10dc # Implicit input
R1+ # Push range(1, input + 1)
Zh # Prime factor exponents
.S2% # Sum mod 2 of each
10dc # Count 1s and 0s
DR1+Zh.S2%SDZKAD # Implicit input
DR1+ # Duplicate and push range(1, input + 1)
Zh # Prime factor exponents
.S2% # Sum mod 2 of each
SDZK # Sum and print without popping
AD # Absolute difference with input
[Julia 1.1], 92 bytes
using Primes
~N=(X=map(n->sum([b for (a,b)=factor(n)]),1:N);[sum(X.%2 .==0),sum(isodd.(X))])
Julia 1.0 appears to be supported by the package Primes.jl, but I haven't been able to import it successfully. Here is the output in Julia 1.1:
julia> VERSION
v"1.1.1"
julia> using Primes
julia> ~N=(X=map(n->sum([b for (a,b)=factor(n)]),1:N);[sum(X.%2 .==0),sum(isodd.(X))])
~ (generic function with 1 method)
julia> map(x -> println(lpad(x,2) * " -> $(~x)"), 1:20);
1 -> [1, 0]
2 -> [1, 1]
3 -> [1, 2]
4 -> [2, 2]
5 -> [2, 3]
6 -> [3, 3]
7 -> [3, 4]
8 -> [3, 5]
9 -> [4, 5]
10 -> [5, 5]
11 -> [5, 6]
12 -> [5, 7]
13 -> [5, 8]
14 -> [6, 8]
15 -> [7, 8]
16 -> [8, 8]
17 -> [8, 9]
18 -> [8, 10]
19 -> [8, 11]
20 -> [8, 12]
This solution could be adapted without Primes in Julia 0.4, when factor was still part of base Julia.
Pyth, 10 bytes
aBsm.&1lPh
Outputs [O(n), E(n)].
Explanation
aB bifurcate the absolute difference of implicit eval(input()) and
s the sum of
m map over implicit range(eval(input()))
.&1 modulo 2 (bitwise and 1)
l the length of
P the list of the prime factors of
h 1 + implicit map lambda variable
Ohm v2, 11 bytes
@€olé;ΣD³a«
Returns a list of [E(n), O(n)]. Note that Ohm v2 formats numbers a little weirdly when they are in a list, but they are definitely the right numbers.
Explained
@€olé;ΣD³a«
@ # Push a range from 1 to the input to the stack
€ ; # To each item in the range from before:
ol # Get the length of the full prime factorization of the item
é # and then push whether the length is even
ΣD # Push two copies of the sum of that list - the first copy is how many numbers are E(n), and the second will be used to calculate how many numbers are O(n)
³a # Get the absolute difference of the input and the E(n) count
« # Pair into a list
Desmos, 101 97 bytes
f(K)=∑_{k=1}^Kmod([1,0]+∑_{n=2}^klog_n(gcd(n^{ceil(log_nk)},k))sign(∏_{a=3}^nmod(n,a-1)),2)
Output is the list \$[E(n),O(n)]\$. It will fail on larger values due to floating point inaccuracies, but I've tested values such as \$1000\$ and it gives the right output, so it's pretty much a nonissue.
Try It On Desmos! - Prettified
A shorter version of the above code technically works, but it fails for values greater than \$15\$ due to floating point errors (so it doesn't even pass all the test cases):
88 84 bytes
f(K)=∑_{k=1}^Kmod([1,0]+∑_{n=2}^klog_n(gcd(n^k,k))sign(∏_{a=3}^nmod(n,a-1)),2)
GeoGebra, 66 bytes
InputBox(n
a=Sum(Zip(Mod(Length(PrimeFactors(a)),2),a,1...n
ai+n-a
Output is in the form \$E(n)+O(n)i\$.
Japt, 12 bytes
Had to sacrifice 2 bytes to handle 1 :\
2Æõk è_ʤ̦X
2Æõk è_ʤ̦X :Implicit input of integer U
2Æ :Map each X in the range [0,2)
õ : Range [1,U]
k : Prime factors of each
è : Count the elements that return true
_ : When passed through the following function
Ê : Length
¤ : To binary string
Ì : Last character
¦X : Not equal to X?
Factor + math.primes.factors, 58 50 bytes
[ dup [1,b] [ factors length odd? ] count tuck - ]
dupCreate an extra copy of the input.[1,b]Create a range from one to the input (inclusive).[ ... ] countCount the number of elements in the range for which[ ... ]returns true.factors length odd?Does it have an odd number of factors?tuck -Subtract the result from the input non-destructively. (Implicit multiple return)
Charcoal, 40 bytes
F…·¹N«≔⁰θWΦι¬﹪ι⁺²λ«≧÷⁺²⌊κι≦¬θ»⊞υθ»IE²№υι
Try it online! Link is to verbose version of code. Explanation:
F…·¹N«
Loop from 1 up to and including n.
≔⁰θ
Assume even kind.
WΦι¬﹪ι⁺²λ«
While the current value has any nontrivial factors: ...
≧÷⁺²⌊κι
... divide it by the lowest such factor, and...
≦¬θ
... flip between even and odd kind.
»⊞υθ
Save the kindness of the current value.
»IE²№υι
Output the counts of even and odd kindness.
Retina 0.8.2, 63 bytes
.+
$*
M!&`.+
+%`^(2*(1+))\2+$
2$1
22|¶
O`2?1
(1)+(21)*
$#1 $#2
Try it online! Link is to test suite that outputs the results for 1..n. Explanation:
.+
$*
Convert to unary.
M!&`.+
List all the numbers from n down to 1.
+%`^(2*(1+))\2+$
2$1
Count the number of prime factors of each number, using repeated 2s as the count. This leaves a lone trailing 1 once all of the prime factors have been counted.
22|¶
Take the parity of the counts of prime factors, so that 1 means that it had an even number and 21 means that it had an odd number, and join all of the results together.
O`2?1
Sort the 1s and 21s separately to make them easier to count.
(1)+(21)*
$#1 $#2
Count the number of 1s and 21s.
Ruby, 72 66 bytes
-6 bytes thanks to Dingus
->n{[e=(1..n).map{|m|m.prime_division.sum{_2}}.count{_1%2<1},n-e]}
Brachylog, 15 bytes
⟦₁{ḋl%₂}ᵍlᵐĊ|;0
Explanation
4 additional bytes needed at the end to deal with the special case of 1.
⟦₁ Range [1, ..., Input]
{ }ᵍ Group by:
ḋl%₂ Length of prime decomposition mod 2
lᵐ Map length
Ċ|;0 Output must have 2 elements; otherwise (Input = 1), Output = [Input, 0]
R, 79 bytes
\(n)c(y<-sum(sapply(1:n,f<-\(n,p=2)sum(x<-!n%%p,if(n>1)f(n/p^x,p+!x))%%2)),n-y)
Returns O(n), E(n).
Helper function f returns the number of prime factors, f%%2 returns whether-or-not this is odd: f<-\(n,p=2)sum(x<-!n%%p,if(n>1)f(n/p^x,p+!x))
JavaScript (ES6), 71 bytes
f=(n,a=[0,0])=>n?f(n-1,a,a[(g=_=>k>n?0:n%k?g(k++):1^g(n/=k))(k=2)]++):a
Commented
f = ( // f is a recursive function taking:
n, // n = input
a = [0, 0] // a[] = output array
) => //
n ? // if n is not equal to 0:
f( // do a recursive call:
n - 1, // decrement n
a, // pass a[]
a[ // update a[]:
( g = // g is a recursive function
_ => // which ignores its parameter
k > n ? // if k is greater than n:
0 // stop the recursion
: // else:
n % k ? // if k is not a divisor of n:
g(k++) // increment k and do a recursive call
: // else:
1 ^ // invert the result
g(n /= k) // divide n by k and do a recursive call
)(k = 2) // initial call to g, starting with k = 2
]++ // increment a[0] or a[1], depending on the
// parity of the number of prime divisors of n
) // end of recursive call
: // else:
a // return a[]
05AB1E, 8 7 bytes
LÓOÉ1Ý¢
Try it online or verify all test cases.
Explanation:
-1 byte by realizing that: amount of prime factors of \$x\$ == sum(exponents of \$x\$'s prime factorization): see that they are the same here.
L # Push a list in the range [1, (implicit) input]
Ò # Get the prime exponents of each inner integer
O # Sum each inner list together
É # Check for each sum whether it's odd
1Ý # Push pair [0,1]
¢ # Count the occurrences of 0 and 1 in the list
# (after which the result is output implicitly)
Mathematica, 40 bytes
Length/@PrimeOmega@Range@#~GroupBy~OddQ&
Output in the form <|False->E(n),True->O(n)|>.
Vyxal, 8 bytes
'ǐ₂;L~ε"
A flagless 8 byter that uses a method that is a little different to the other answer.
7 bytes using this approach with a flag:
Vyxal o, 7 bytes
'ǐ₂;L…ε
Jelly, 8 bytes
RÆE§ḂSṄạ
RÆE§ḂSṄạ
R - Range [1, input]
ÆE - For each, get a list of the prime exponents
§ - Sum each
Ḃ - Modulo each by 2
S - Sum
Ṅ - Print (with a trailing newline)
ạ - Get the absolute difference between this and the input (also implicitly printed)
J, 19 bytes
(-,])1#.2|1#@q:@+i.
1...+i.1 2 ... n#@q:Length#of prime factorsq:of each1#.2|Sum of even lengths(-,])Input minus that sum-catted with,that sum]
PARI/GP, 31 bytes
n->sum(i=1,n,I^(bigomega(i)%2))
Outputs a complex number where the real part is \$E(n)\$ and the imaginary part is \$O(n)\$.