P40
projecteuler.net

Champernowne's Constant

ℹ️Published on Friday, 28th March 2003, 06:00 pm; Solved by 87071;
Difficulty rating: 5%

An irrational decimal fraction is created by concatenating the positive integers: $$0.12345678910{\color{red}\mathbf 1}112131415161718192021\cdots$$

It can be seen that the $12$th digit of the fractional part is $1$.

If $d_n$ represents the $n$th digit of the fractional part, find the value of the following expression. $$d_1 \times d_{10} \times d_{100} \times d_{1000} \times d_{10000} \times d_{100000} \times d_{1000000}$$



Soluzione

Qui l'idea è di vedere come si compone il numero definito, ottenuto concatenando tutti gli interi positivi, e considerare le cifre \(d_1, d_{10}, d_{100}, \ldots\) quando le incontriamo. Per tenerne traccia, usiamo un cursore che si sposta di volta in volta, anche in base alla lunghezza del numero (se concateniamo 8 si sposterà di uno, se concateniamo 800 si sposterà di tre).

P = 1 # risposta, il prodotto da calcolare
cursore = 0 # puntatore alla cifra corrente
n = 1 # variabile su cui scorriamo per definire il decimale
stops = 10 .^ [0,1,2,3,4,5,6] # posti in cui fermarsi a prendere dₙ
while cursore < 10^6
	cifre = reverse(digits(n))
	for i in 1:length(cifre)
		global cursore += 1
		if cursore in stops
			println("La cifra $cursore-esima era $(cifre[i])")
			global P = P * cifre[i]
		end
	end
	global n += 1
end
@show P
La cifra 1-esima era 1
La cifra 10-esima era 1
La cifra 100-esima era 5
La cifra 1000-esima era 3
La cifra 10000-esima era 7
La cifra 100000-esima era 2
La cifra 1000000-esima era 1
P = 210

Last modified: August 18, 2025. Website built with Franklin.jl and the lovely Julia programming language.