How many different values can the function return?

How many different values can the function return?

Other urls found in this thread:

en.wikipedia.org/wiki/Radical_of_an_integer
twitter.com/NSFWRedditImage

8 choose 2 = 28

8 choose 0 + 8 choose 1 + ... + 8 choose 8

You should be able to prove that

infinitely many

any integer is either a product of primes or prime itself, but you've only accounted for 8 primes. there are infinitely more primes available to construct integers

8! + 1

2^8.

The factors are all prime (thus each modulus is independent of another) and can only be applied once. There are 8 statements that can either be true or false based on the factors of x. Therefore, there are 2^8 possible return values for n. Additionally, the max value for n is 9699690, so it is not enough to overflow the presumably signed 32-bit int. Also, x being negative has no impact on this function. The total range of values is 1 - 9699690.

2^8 +1 = 256+1 = 257

I would say:
40321
but only when we don't have 16-bit data model (so int is alocated on 32-bits)
In other way, we couldn't process for example x=9699690 value

>f(23) returns 1
what a shitty function

ok, I totally wrong here.
If we would have only 3 first instead of 8 conditions then we would have:
1, 2, 3, 5, 6, 10, 15, 30
2^3, so i thing it would be 2^8 like some other alredy wrote

Looks to be a little more than 250.

Jesus fucking christ dude. COMBINATORICS. This is no more than counting it with n choose k and then using identities to see it is equal to 2^8 = 256

I can't believe CS fags can't even do that and need to a whole algorithm and graph to crack an elementary problem.

Calm your tits dude, there's nothing wrong with experimentally verifying your solutions whenever possible.

You saying "it's about 250" shows you didn't even have the solution so you aren't verifying anything. You literally are too study for combinatorics and tried to brute force the problem.

If you start from 1, what's the minimum number that gives you all the combinations?

2^8?

beat me to it.

a lot

It actually is 2^8, i fucked up with the +1

I'll be honest.

I study CS and I don't understand how 2^8 is the answer..

Each statement can be true or false. The true or falseness of a statement contributes independent values to the final output (the numbers are coprime). Thus this is the same as the number of combinations of true and false there are for a set of 8 distinct statements, which is 2^8.

This function only returns a single value.

There are nine statements though.

What if x == 23?

256

>There are nine statements though.
No there aren't
>What if x == 23?
The function returns 1

holy fuck people on sci are stupid
every if statement can be true independently from each other, because the denominators for the modulos are all primes.
furthermore, each if-statement being true gives an individual fingerprint for the return value n
pretty obvious that 2^8=256 is the answer

there are no 9th statements,
if x=23, then all 8 statements have false value and that case is also contained in 2^8

Divisibility by two different primes is independent, and the numbers in these conditionals are all prime. Therefore, the conditionals are independent, and so their valuations may be treated as bits in an 8-bit string with 1 indicating true and 0 indicating false. It's now simply a case of counting the total number of 8-bit strings, turning this into an elementary application of the Binomial Theorem.

In case the application isn't clear: Each position in an 8-bit string can either be 1 or 0. There are (8 \choose k) ways to choose a bit string with exactly k bits set to 1. The total number of possible 8-bit strings is the sum of these (8 \choose k) terms for 0

Oh I get what you're saying now. Thanks

these are correct

uh.. except the last one
delete that +1 and it'd be correct

>these are correct
>quotes posts that give different answers

if you don't see how the first post is equal to the second one you need to review the binomial theorem

I corrected myself here

2^8
it either satisfies each modulus or it doesn't
t. combinatorics specialist

>mathematica

9?

oh right, 0 fits them all, so 10.

and I guess negatives too
19

def f(x):
p = [2,3,5,7,11,13,17,19]
n = 1
for k in p:
if x % k == 0:
n *= k
return n

d = set()

for x in xrange(9699690):
d.add(f(x))

print len(d)

result: 256

n can only be 9 different values

this

1*2*3*5*7*11*13*17*19

looks like code a math student would write.
"I learned programming in a weekend guys, CS is bullshit."

You disgusting pig

you only speak computer language to a plastic box.
I am a mathematician
how dare you

Look closer brainlet

Infinite because it doesn't check whether the value of x is within the range of int.

>inb4 engineer

>doesn't check whether the value of an int is within the range of an int
Average /g/entleman, ladies and gentlemen.

this looks like a truncated radical.

radical of a natural number x=p1^m1 * p2^m2 *...* pn^mn (prime factorization) would be p1*p2*...*pn
en.wikipedia.org/wiki/Radical_of_an_integer

but yeah each of the finitely many listed primes can occur in the result with an exponent of 0 or 1, therefore clearly the answer is 2 to the power of however many primes are explicitly listed.

What if x is negative?

Why is the +1 not necessary? plz explain

x % p is 0 iff x is divisible by p. The sign of x is completely irrelevant

see think of the radical in terms of the exponents prime factorization, it makes it very obvious whats going on.

or alternatively, explain why you'd think the +1 case would be necessary.