1. How many integers from 1 to 2018 inclusive have a base three representation that contains at least one digit 2?
2. Consider a cube on a table with each of the faces painted a different color. Suppose you were to pick up the cube, turn it around, then return it to its original position with the same colors permuted. Of the ways to reposition the cube, in how many cases does no color occupy its original position?
excuse me why does this just happen to be a question in the aops homework? In high school math contest? Problems 3 and 4?
;i=0;x=0;c=0;m=b;a=b[0];
cycle: s=(b[i]%10);if(s==2, c=c+1, 0);b[i]=int(b[i]/10);if(b[i]!=0, goto cycle,0);
if(c>=1,goto end, goto next);end:printm[i],", ",;x=x+1;
next:c=0;i++;if(i< count b, goto cycle, discard=0;print"Total =", x
OUTPUT: 1891
Solution for #2:
\({}\)
Solve this using the derangement formula:
\(!n = \left [\dfrac{n!}{e} \right] \qquad | \qquad \text { where [ ] is the nearest integer, and (e) is Euler’s Number ~(2.71828...).} \\\)
In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position. In other words, a derangement is a permutation that has no fixed points. Source: https://en.wikipedia.org/wiki/Derangement
\(!6 = \left [\dfrac{6!}{e} \right] = 265 \; \text {sets where no color occupies its original position.}\\ \)
GA
You may be right. I may reconsider my answer. This question seems to lack clarity and precision.
Suppose you were to pick up the cube, turn it around, then return it to its original position with the same colors permuted. Of the ways to reposition the cube, in how many cases does no color occupy its original position?
I interpret: “return it to its original position with the same colors permuted” to mean any color may be swapped with any other color. If so, then the derangement formula is correct.
However, if it means the colors may only be swapped by rotating the cube then the full set of permutations are not attainable, only the permutations relative to it orientation in space. The portion of derangements will be reduced but they probably will not be a(n) (integer) factor of (e).
GA